ebethus/laravel-vv-logs-viewer
Simple in-app Laravel/Lumen log viewer. Install via Composer, register the service provider, and add a route to LogViewerController@index to browse log files (with or without log rotation). No public assets or vendor routes needed.
Installation:
composer require rap2hpoutre/laravel-log-viewer
Update config/app.php to include the service provider:
'providers' => [
// ...
Rap2hpoutre\LaravelLogViewer\LogViewerServiceProvider::class,
],
Publish Config (Optional):
php artisan vendor:publish --provider="Rap2hpoutre\LaravelLogViewer\LogViewerServiceProvider"
This creates a config/log-viewer.php file for customization.
Route the Controller:
Add this to your routes/web.php:
Route::get('/logs', 'Rap2hpoutre\LaravelLogViewer\LogViewerController@index');
(Note: For Laravel 8+, use use statement or fully qualified class name.)
First Use Case:
Visit /logs in your browser. The package will display a paginated list of log files (e.g., laravel.log, rotated logs like laravel-2023-10-01.log), with the ability to view their contents line-by-line.
Log File Discovery:
storage/logs/ (default) or a custom path (configurable via log-viewer.php).laravel.log, laravel-*.log) out of the box.Viewing Logs:
Integration with Laravel Debugging:
dd() or dump() for quick log inspection during development.tail -f storage/logs/laravel.log with the web interface for real-time monitoring.Customization:
resources/views/vendor/log-viewer/ to match your app’s design.Route::get('/logs', function () {
return app('log-viewer')->index();
})->middleware('auth');
config/log-viewer.php:
'log_path' => storage_path('custom-logs'),
Programmatic Access:
$logs = app('log-viewer')->getLogs();
$logContent = app('log-viewer')->getLogContent('laravel.log');
Log Filtering by Level:
error, info). Modify the LogViewerController to pass a $level parameter to the getLogs() method or override the view logic.Export Logs:
Route::get('/logs/export', function () {
return app('log-viewer')->exportLogs();
});
exportLogs() method in a service class.Real-Time Updates:
Log Anonymization:
getLogContent() method or create a middleware.Permission Issues:
www-data, nginx) has read access to storage/logs/.chmod -R 755 storage/logs/
chown -R www-data:www-data storage/logs/
Rotated Logs Not Showing:
laravel-{date}.log). If using a custom rotator, ensure the log-viewer.php config includes the correct glob pattern:
'log_pattern' => 'laravel-*.log',
Large Log Files:
per_page setting in config/log-viewer.php or optimize the log rotation strategy.Caching Headaches:
php artisan cache:clear
config/log-viewer.php for development:
'cache_enabled' => false,
Lumen Compatibility:
bootstrap/app.php:
$app->register(Rap2hpoutre\LaravelLogViewer\LogViewerServiceProvider::class);
CSRF Protection:
Route::get('/logs', 'LogViewerController@index')->middleware('web');
Log Viewer Not Loading:
storage/logs/ directory exists and contains log files.Blank Page:
resources/views/vendor/log-viewer/ directory exists (publish the views if missing).storage/logs/laravel.log.Search Not Working:
// Example: Modify the search logic in LogViewerController
preg_match('/' . preg_quote($searchTerm, '/') . '/i', $line)
Performance Bottlenecks:
getLogContent() method. Large files may benefit from streaming or chunked reading.Custom Log Sources:
LogViewerService to support non-Laravel log files (e.g., Nginx, MySQL). Override the getLogs() method to include additional paths or parsers.Log Formatting:
API Endpoint:
Route::get('/api/logs', function () {
return response()->json(app('log-viewer')->getLogs());
});
Log Archiving:
storage/logs/archive/) via a scheduled command:
// Example: app/Console/Commands/ArchiveLogs.php
use Rap2hpoutre\LaravelLogViewer\LogViewerService;
class ArchiveLogs extends Command {
protected $logViewer;
public function __construct(LogViewerService $logViewer) {
$this->logViewer = $logViewer;
}
public function handle() {
$this->logViewer->archiveOldLogs();
}
}
How can I help you explore Laravel packages today?