shaonmajumder/log-viewer
Beautiful, secure Laravel log viewer for Laravel 9–11 and PHP 8+. Auto-discovers log files, highlights levels, supports themes, search and level filtering, context expansion, tail mode, auto-refresh, and downloading full or filtered output.
Installation
composer require shaonmajumder/log-viewer
Publish config and views:
php artisan vendor:publish --tag=log-viewer-config
php artisan vendor:publish --tag=log-viewer-views
First Use Case
Access /log-viewer in your browser. The package auto-detects Laravel log files (laravel.log, rotated logs) and displays them with color-coded levels (ERROR, WARNING, INFO, DEBUG).
config/log-viewer.php (adjust route_prefix, middleware, auth_required)./log-viewer (customizable via route_prefix).resources/views/vendor/log-viewer/index.blade.php for UI tweaks.Log Discovery The package automatically scans for:
laravel.loglaravel-YYYY-MM-DD.log)log_paths in config).Filtering & Search Use the UI controls for:
±5 lines around matches).Access Control
auth_required = true).allowed_emails or a callback in authorize config.auth_required = false (e.g., for internal tools).Theming
Dark Ink, Dark Graphite, Dark Forest).localStorage.Download Logs
/log-viewer/download.middleware in config (e.g., ['web', 'admin']).log-viewer::layouts.app for consistent branding.authorize callback for role-based access:
'authorize' => function ($user) {
return $user->isAdmin(); // Example
}
log_paths:
'log_paths' => [
storage_path('logs/custom.log'),
],
Route Conflicts
laravel.log.*).route_name_prefix (default: log.viewer.).Auth Bypass
auth_required = true but users can’t log in, check:
['web']).authorize callback.Log File Permissions
storage/logs) is readable by the web server.Large Logs
⏱️) may lag with >10K lines. Use limits (e.g., 1000 lines).No Logs Displaying?
log_paths in config includes your log files.chmod -R 755 storage/logs).Theme Not Saving?
localStorage or check for JavaScript errors in browser console.Download Fails?
storage_path('logs') is writable.Custom Highlighting
Override highlightLogContent() in a service provider:
LogViewer::extend(function ($content) {
return preg_replace('/\bERROR\b/i', '<span class="custom-error">ERROR</span>', $content);
});
Add Log Sources
Extend LaravelLogViewerServiceProvider to include non-Laravel logs:
$this->app->bind('log-viewer.source', function () {
return new CustomLogSource();
});
Modify UI
Override resources/views/vendor/log-viewer/index.blade.php or extend the layout.
Real-Time Updates Use Laravel Echo/Pusher to sync log changes across instances (advanced).
auth_required vs Middleware:
auth middleware redirects guests).auth_required is a secondary check (useful for custom logic).allowed_emails:
[] to disable.['admin@example.com'].Theme Persistence:
localStorage. For SSO environments, consider server-side theme storage.auth_required = false for quick access.allowed_emails or authorize callback.tail -n 1000 in a cron job.How can I help you explore Laravel packages today?