rap2hpoutre/laravel-log-viewer
View Laravel and Lumen log files in the browser with a lightweight log viewer. Install via Composer, register the service provider, and add a single route to LogViewerController—no public assets or vendor routes. Works with rotated logs.
composer require rap2hpoutre/laravel-log-viewer in your project root.routes/web.php:
Route::get('logs', [\Rap2hpoutre\LaravelLogViewer\LogViewerController::class, 'index']);
/logs in your browser. The viewer will display all logs from storage/logs/laravel.log (or your configured log path) with syntax highlighting and search functionality.Key First Steps:
Route::get('logs', ...)->middleware('auth')).Debugging Errors:
Exception, Error, or specific error messages.Monitoring Deployments:
Collaboration:
log.blade.php).Custom Log Paths:
php artisan vendor:publish --provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider".config/logviewer.php to specify paths like:
'paths' => [
storage_path('logs/custom.log'),
storage_path('logs/debug.log'),
],
Log Filtering:
namespace App\Http\Controllers;
use Rap2hpoutre\LaravelLogViewer\LogViewerController as BaseController;
class LogViewerController extends BaseController {
public function index() {
$logs = $this->getLogs()->filterBySeverity('error'); // Hypothetical method
return view('vendor.laravel-log-viewer.log', ['logs' => $logs]);
}
}
Integration with Log Rotation:
logging.php config uses the daily channel for automatic log splitting (e.g., laravel-2023-10-01.log).CI/CD Logging:
Route::get('ci-logs', [\Rap2hpoutre\LaravelLogViewer\LogViewerController::class, 'index'])
->middleware(['auth', 'env:staging']);
Config Cache Issues:
InvalidArgumentException or blank page after installation.php artisan config:clear and php artisan view:clear.post-install scripts or package.json:
"scripts": {
"post-install": "php artisan config:clear"
}
Permission Errors:
storage/logs/laravel.log.www-data, apache) has read access:
chmod -R 755 storage/logs/
chown -R www-data:www-data storage/logs/
Log Rotation Confusion:
.gz).logging.php or pre-process logs:
'channels' => [
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'compress' => false, // Disable compression
],
],
Performance in Production:
logrotate).maxFile config to limit file size:
'maxFile' => 10240, // 10MB
Log Viewer Not Loading:
LogViewerController is registered in config/app.php.Custom View Not Applying:
resources/views/vendor/laravel-log-viewer/log.blade.php) is not cached.php artisan view:clear.Missing Logs:
config/logging.php).Custom Log Parsing:
LogViewerController to parse logs before rendering:
public function index() {
$logs = $this->getLogs()->map(function ($log) {
$log['custom_field'] = $this->parseLog($log['message']);
return $log;
});
return view('vendor.laravel-log-viewer.log', ['logs' => $logs]);
}
Add Export Functionality:
public function export($format = 'json') {
$logs = $this->getLogs();
return response()->json($logs->toArray())->header('Content-Type', 'application/json');
}
Route::get('logs/export', [LogViewerController::class, 'export']);.Real-Time Logs:
Multi-Environment Logs:
'paths' => [
env('LOG_PATH') ?: storage_path('logs/laravel.log'),
],
/logs in production without strict authentication (e.g., IP whitelisting, 2FA).log() carefully.Ctrl+F for search and Esc to clear the search in most browsers.log.blade.php for better readability:
<style>
body.log-viewer { background-color: #1a1a1a; color: #e0e0e0; }
.log-entry { background-color: #2d2d2d; }
</style>
highlight config to customize syntax colors:
'highlight' => [
'error' => 'red',
'warning' => 'orange',
'info' => 'green',
],
logrotate to keep logs manageable:
# Example logrotate config (/etc/logrotate.d/laravel)
/var/www/storage/logs/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 www-data:www-data
sharedscripts
postrotate
invoke-rc.d apache2 reload > /dev/null 2>&1
endscript
}
How can I help you explore Laravel packages today?