elkadrey/laravel-log-viewer
Lightweight Laravel/Lumen log viewer. Install via Composer, register the service provider, and add a route to LogViewerController@index to browse your app logs in the browser. No public assets or vendor routes; supports rotated logs.
Installation:
composer require elkadrey/laravel-log-viewer
(Note: The README mentions rap2hpoutre/laravel-log-viewer, but the package name in the prompt is elkadrey/laravel-log-viewer. Verify the correct package name in your project.)
Publish Configuration (optional):
php artisan vendor:publish --provider="Elkadrey\LogViewer\LogViewerServiceProvider"
(This generates a config/log-viewer.php file for customization.)
Add Route:
In routes/web.php:
Route::get('/logs', 'Elkadrey\LogViewer\LogViewerController@index');
(For Lumen, use Route::get('/logs', 'Elkadrey\LogViewer\LogViewerController@index'); in routes/web.php.)
First Use Case:
Visit /logs in your browser to view Laravel’s log files (e.g., storage/logs/laravel.log) in a structured UI. Supports filtering by date, level (e.g., error, info), and keyword search.
Log Filtering:
debug, info, warning, error, or critical via checkboxes.auth, database).error logs from the last hour containing stripe.Integration with Existing Logs:
config/logging.php are needed.laravel-2025-04-06.log) out of the box.Custom Log Files:
storage/logs/custom.log) by modifying the LogViewerServiceProvider:
$this->app['log-viewer']->addLogFile('custom.log');
queue-worker.log).API Access (Advanced):
LogViewerController:
use Elkadrey\LogViewer\LogViewerController;
class ApiLogViewerController extends LogViewerController {
public function index() {
$logs = parent::getLogs(); // Reuse existing logic
return response()->json($logs);
}
}
Log Annotations:
LogEntry model (if the package uses one) or pre-processing logs with metadata:
// In a middleware or service provider
Log::withContext(['user_id' => auth()->id(), 'request_id' => request()->header('X-Request-ID')]);
Log Rotation Conflicts:
log-max-files in config/logging.php is set appropriately (e.g., 30).php artisan log:rotate or adjust the rotation schedule.Permission Issues:
storage/logs/, which may require permissions:
chmod -R 775 storage/logs
storage:link to ensure symlinks are accessible.Large Log Files:
// In config/log-viewer.php
'chunk_size' => 1000, // Process 1000 lines at a time
tail -f in production to stream logs in real-time (requires custom integration).Lumen Compatibility:
LogViewerServiceProvider is registered in bootstrap/app.php:
$app->register(\Elkadrey\LogViewer\LogViewerServiceProvider::class);
Caching Logs:
php artisan cache:clear
config/log-viewer.php for development:
'cache' => env('APP_ENV') !== 'local',
Log Entry Parsing:
LogEntry parser (if the package uses one). Override the parser in a service provider:
$this->app->bind('log-viewer.parser', function() {
return new CustomLogParser();
});
Missing Logs:
storage/logs/laravel.log. Test with:
Log::error('Test log entry');
APP_LOG environment variable to confirm the log channel.Performance Bottlenecks:
barryvdh/laravel-debugbar) to profile the /logs route:
composer require barryvdh/laravel-debugbar
sqlite for indexed logs).Custom Log Formats:
LogParser interface:
class SyslogParser implements LogParser {
public function parse($logEntry) { ... }
}
$this->app->bind('log-viewer.parser', SyslogParser::class);
UI Customization:
resources/views/vendor/log-viewer/ to modify the UI (e.g., add a dark mode toggle).index.blade.php to include a "Copy to Clipboard" button for log entries.Alerting Integration:
error logs). Use a service provider:
$this->app->afterResolving('log-viewer', function($viewer) {
$viewer->setAlertCallback(function($log) {
if (strpos($log->message, 'failed') !== false) {
// Send alert
}
});
});
Log Archiving:
LogViewer class to move old logs to storage/logs/archive/:
$viewer->archiveLogs('laravel.log', 30); // Archive logs older than 30 days
How can I help you explore Laravel packages today?