everysecond/laravel-log-viewer
Lightweight Laravel/Lumen log viewer. Install via Composer and add a route to LogViewerController to browse application logs in the browser. No public assets or vendor routes required; supports rotated logs and works across multiple Laravel versions.
Installation:
composer require rap2hpoutre/laravel-log-viewer
(Note: The README incorrectly lists everysecond/laravel-log-viewer; the correct package is rap2hpoutre/laravel-log-viewer.)
Publish Config (Optional):
php artisan vendor:publish --provider="Rap2hpoutre\LaravelLogViewer\LogViewerServiceProvider"
(Default config is minimal; customization is rare but useful for log paths.)
Route Registration:
Add to routes/web.php:
Route::get('/logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index');
(No middleware needed by default; secure with auth or can if required.)
First Use Case:
Visit /logs to see a real-time log viewer with:
error, info).Debugging in Development:
/logs to verify if a bug’s logs exist before diving into storage/logs.?level=error to the URL to focus on critical logs.Production Support:
Route::get('/logs', [LogViewerController::class, 'index'])->middleware('can:view-logs');
Integration with Existing Tools:
single, daily), ensure the log config path is correct in config/log-viewer.php.Testing:
storage/logs/laravel.log and verifying the viewer displays them.Log::shouldReceive() to test log filtering logic.'log_path' => storage_path('logs/custom/laravel.log'),
'auto_refresh' => false in config to reduce server load.resources/views/vendor/log-viewer/index.blade.php) to match your app’s CSS.Incorrect Package Name:
The README lists everysecond/laravel-log-viewer, but the correct package is rap2hpoutre/laravel-log-viewer. Double-check during installation.
Log Rotation Conflicts:
laravel.log.1), the viewer may not show them by default. Use the "Browse" feature to manually select older files.log-rotate isn’t deleting logs before they’re viewed.Performance on Large Logs:
memory_limit temporarily.?lines=100 to limit displayed lines.Permission Issues:
www-data) has read access to storage/logs/.chmod -R 755 storage/logs/
chown -R www-data:www-data storage/logs/
Lumen Compatibility:
bootstrap/app.php:
$app->register(\Rap2hpoutre\LaravelLogViewer\LogViewerServiceProvider::class);
config/log-viewer.php matches your config/logging.php path setting.
// config/logging.php
'path' => storage_path('logs/laravel.log'),
storage/logs/laravel.log (ironic but common). Enable Laravel’s debug mode:
APP_DEBUG=true
debug, info, notice, warning, error, critical). Custom levels (e.g., spam) won’t filter.Custom Log Levels:
Extend the LogLevel class to support custom levels:
namespace App\Extensions;
use Rap2hpoutre\LaravelLogViewer\LogLevel;
class CustomLogLevel extends LogLevel {
public static function spam(): string { return 'spam'; }
}
Then update the controller to use your class.
Add Context to Logs:
Override the LogViewerController to inject additional context (e.g., user ID, request data) into log lines:
public function index() {
Log::info('Custom context', ['user_id' => auth()->id()]);
return parent::index();
}
API Endpoint: Convert the viewer into an API by extending the controller:
public function apiLogs(Request $request) {
return response()->json($this->getLogs($request));
}
(Useful for integrating with frontend frameworks like Vue/React.)
Log Anonymization:
Filter sensitive data (e.g., passwords) before displaying logs. Hook into the getLogs method:
protected function filterLogs(array $logs) {
return array_map(function ($log) {
return str_replace('password=".*?"', 'password="[FILTERED]"', $log);
}, $logs);
}
How can I help you explore Laravel packages today?