fishtail/laravel-log-viewer
Simple Laravel/Lumen log viewer for Laravel 5–8 (compatible with 4.2). Install via Composer, register the service provider, and add a route to LogViewerController@index. No published assets or vendor routes; works with rotated logs.
Installation:
composer require rap2hpoutre/laravel-log-viewer
Publish Config (Optional):
php artisan vendor:publish --provider="Rap2hpoutre\LaravelLogViewer\LogViewerServiceProvider"
(Default config works out-of-the-box, but publishing allows customization.)
Route Integration:
Add to routes/web.php:
Route::get('/logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index');
(Use middleware like auth if needed.)
First Use Case:
Visit /logs to view real-time Laravel logs with:
Log Filtering:
error, critical) or debug logs.Integration with Existing Systems:
Route::get('/logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index')->middleware('can:view-logs');
class ApiLogController extends \Rap2hpoutre\LaravelLogViewer\LogViewerController {
public function showJson() {
return response()->json($this->getLogs());
}
}
Log Rotation Handling:
storage/logs/laravel-2023-10-01.log) and merges them into a unified view.log_viewer.log_files in config/log-viewer.php to specify custom paths or exclude files.Customizing Output:
resources/views/vendor/log-viewer/index.blade.php) to:
Programmatic Access:
$logs = app(\Rap2hpoutre\LaravelLogViewer\LogViewerService::class)->getLogs();
Log Annotations:
Add context to logs by extending the LogEntry model:
// In a service provider
$this->app->extend('log-viewer.entry', function ($entry) {
$entry->setCustomAttribute('user_id', auth()->id());
return $entry;
});
Real-Time Updates: Combine with Laravel Echo/Pusher to push new logs to clients:
// Frontend (Vue/React)
Echo.channel('logs')
.listen('LogUpdated', (e) => {
// Update UI with new log entry
});
Log Export: Add a download button to export logs as JSON/CSV:
// In a custom controller method
public function exportLogs() {
$logs = $this->getLogs();
return response()->json($logs)->header('Content-Type', 'application/json');
}
Log File Permissions:
storage/logs/ is writable by the web server:
chmod -R 775 storage/logs/
Log Rotation Conflicts:
logrotate), the viewer may miss recent entries.log_viewer.log_files to include all rotated files or adjust rotation settings to keep recent logs in a single file.Large Log Files:
log_viewer.max_log_size to limit file size or pre-process logs with log_viewer.filter.Lumen Compatibility:
bootstrap/app.php:
$app->register(\Rap2hpoutre\LaravelLogViewer\LogViewerServiceProvider::class);
Monolog-Specific Issues:
storage/logs/laravel.log or update log_viewer.log_files.Blank Screen:
storage/logs/laravel.log for PHP errors.LogViewerController.Logs Not Loading:
log_viewer.filter in config to rule out custom filtering issues.Search Not Working:
log_viewer.searchable_fields includes all relevant log properties (default: ['message', 'context']).Configuration Shortcuts:
'auto_refresh' => env('APP_ENV') !== 'production',
'visible_levels' => ['error', 'critical'],
Extending Functionality:
public function clearLogs() {
$files = glob(storage_path('logs/*.log'));
foreach ($files as $file) {
unlink($file);
}
return back()->with('status', 'Logs cleared!');
}
Security:
Route::middleware(['throttle:10,1'])->group(function () {
Route::get('/logs', 'LogViewerController@index');
});
Performance:
$logs = Cache::remember('log_viewer_entries', now()->addHours(1), function () {
return $this->getLogs();
});
Local Development:
log_viewer.log_files to monitor specific log files:
'log_files' => [
storage_path('logs/laravel.log'),
storage_path('logs/debug.log'),
],
How can I help you explore Laravel packages today?