Log Viewer (Latest 50 Entries)

@php $path = storage_path('logs/laravel.log'); $logs = file_exists($path) ? explode("\n", trim(file_get_contents($path))) : []; $entries = []; $entry = ""; foreach ($logs as $line) { if (preg_match('/^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\]/', $line)) { if ($entry) $entries[] = $entry; $entry = $line . "\n"; } else { $entry .= $line . "\n"; } } if ($entry) $entries[] = $entry; $entries = array_reverse($entries); $entries = array_slice($entries, 0, 50); // ✅ Show only latest 50 entries @endphp @foreach ($entries as $index => $entry) @php preg_match('/\[(.*?)\] (\w+)\.(\w+): (.*?)(?={|$)/', $entry, $matches); $timestamp = $matches[1] ?? 'Unknown Time'; $env = $matches[2] ?? 'local'; $level = strtolower($matches[3] ?? 'log'); $summary = $matches[4] ?? 'No message'; @endphp
[{{ $timestamp }}] {{ strtoupper($level) }}: {{ $summary }}
{!! e($entry) !!}
@endforeach