Installation
composer require rap2hpoutre/laravel-log-viewer
Add the service provider to config/app.php under providers:
Mannysoft\LogViewer\LogViewerServiceProvider::class,
Publish Config (Optional) Publish the default config to customize log paths or filters:
php artisan vendor:publish --provider="Mannysoft\LogViewer\LogViewerServiceProvider"
Edit config/log-viewer.php if needed.
First Use Case
Add a route to access the log viewer (e.g., in routes/web.php):
use Mannysoft\LogViewer\Controllers\LogViewerController;
Route::get('/logs', [LogViewerController::class, 'index']);
Visit /logs to see a real-time log viewer interface.
Log Filtering
error, info) via URL query:
/logs?level=error
/logs?from=2024-01-01&to=2024-01-31
/logs?search=authentication
Integration with Existing Logs
single, daily) without manual configuration.Customizing Log Paths
config/log-viewer.php:
'paths' => [
storage_path('logs/custom-laravel.log'),
storage_path('logs/another-service.log'),
],
Access Control
auth or custom middleware):
Route::get('/logs', [LogViewerController::class, 'index'])->middleware('can:view-logs');
Programmatic Access
LogViewer facade to fetch logs programmatically:
use Mannysoft\LogViewer\Facades\LogViewer;
$logs = LogViewer::getLogs(['level' => 'error']);
Extending Log Parsing
LogParser:
$this->app->bind('logviewer.parser', function () {
return new CustomLogParser();
});
Mannysoft\LogViewer\Contracts\LogParser to handle custom log formats.Adding Log Actions
public function deleteLogs(Request $request) {
$this->logViewer->deleteLogs($request->input('files'));
return back()->with('success', 'Logs deleted');
}
Real-Time Updates
Log Export
public function exportLogs(Request $request) {
return response()->streamDownload(function () {
echo json_encode($this->logViewer->getLogs($request->all()));
}, 'logs.json');
}
Permission Issues
www-data, nginx) has read access to log files:
chmod -R 755 storage/logs/
chown -R www-data:www-data storage/logs/
Log Rotation Conflicts
logrotate with copytruncate or configure Laravel’s Log::rotate() to avoid gaps.Large Log Files
tail -f for real-time streaming (requires custom implementation).Caching Headaches
Cache::remember()). Logs are dynamic!Middleware Conflicts
trustedproxy or throttle, ensure the log viewer route is excluded:
Route::middleware(['web', 'log-viewer'])->group(function () {
Route::get('/logs', [LogViewerController::class, 'index']);
});
Check Log Paths
config/log-viewer.php paths match your actual log locations:
dd(config('log-viewer.paths'));
Enable Debug Mode
APP_DEBUG=true to see detailed errors if the viewer loads blank.Log Parser Issues
LogParser implementation:
$this->app->singleton('logviewer.parser', function () {
return new \Mannysoft\LogViewer\Parsers\MonologParser();
});
File Permissions
tail -n 10 storage/logs/laravel.log
Custom Log Formats
UI Customization
resources/views/vendor/log-viewer/index.blade.php) to add:
API Endpoint
public function apiLogs(Request $request) {
return response()->json($this->logViewer->getLogs($request->all()));
}
Log Anonymization
$this->app->afterResolving('logviewer.parser', function ($parser) {
$parser->setFilter(function ($log) {
return preg_replace('/password=[^&]+/', 'password=***', $log);
});
});
Alerting Integration
error logs):
LogViewer::listen(function ($logs) {
if (collect($logs)->contains('authentication failed')) {
// Send alert
}
});
How can I help you explore Laravel packages today?