dipeshshihora/laravel-log-viewer
Simple log viewer for Laravel 9–12 and Lumen. Install via Composer, add a /logs route to LogViewerController, and browse storage logs with a plain HTML UI. Optional publishing for views/config; supports patterns, multiple paths, paging, and max file size limits.
Installation:
composer require dipeshshihora/laravel-log-viewer
Publish the config file (if needed):
php artisan vendor:publish --provider="Dipeshshihora\LogViewer\LogViewerServiceProvider"
First Use Case:
app/Http/Kernel.php:
'web' => [
\Dipeshshihora\LogViewer\Middleware\LogViewerMiddleware::class,
],
/logs route (default) or configure a custom route in config/log-viewer.php.Quick View:
/logs in your browser to see a filtered, searchable log interface.storage/logs/laravel.log (adjustable in config).Log Filtering:
/logs?level=error&search=authentication
level (debug, info, warning, error, critical), search, from, to.Custom Log Files:
config/log-viewer.php:
'log_file' => storage_path('logs/custom.log'),
log_files array:
'log_files' => [
storage_path('logs/laravel.log'),
storage_path('logs/custom.log'),
],
Integration with Existing Routes:
auth):
Route::get('/logs', [LogViewerController::class, 'index'])->middleware('auth');
namespace App\Http\Controllers;
use Dipeshshihora\LogViewer\Controllers\LogViewerController as BaseController;
class LogViewerController extends BaseController {
public function index() {
// Pre-process logs (e.g., mask sensitive data)
$logs = parent::index();
return view('log-viewer::index', compact('logs'));
}
}
Blade Customization:
php artisan vendor:publish --tag=log-viewer-views
resources/views/vendor/log-viewer/index.blade.php to add columns, buttons, or styling.API Access:
LogViewerFacade to fetch logs programmatically:
use Dipeshshihora\LogViewer\Facades\LogViewer;
$logs = LogViewer::getLogs(['level' => 'error']);
Large Log Files:
log_max_lines in config to limit results:
'log_max_lines' => 5000,
Permission Issues:
www-data) has read access to storage/logs/:
chmod -R 755 storage/logs/
Log Rotation:
config/logging) or a tool like logrotate.Monolog-Specific Quirks:
Route Conflicts:
/logs route may conflict with existing routes. Always check routes/web.php and adjust the route in config/log-viewer.php:
'route' => 'admin/logs',
Log Format Issues:
tail -n 10 storage/logs/laravel.log | jq
Middleware Not Triggering:
app/Http/Kernel.php and the route is accessible.Route::get('/test-log-viewer', function () {
return LogViewer::getLogs();
});
Custom Controller Overrides:
parent::index()) to retain default functionality.Caching:
php artisan cache:clear
php artisan view:clear
Custom Log Parsers:
LogParser class to support non-JSON logs:
namespace App\Services;
use Dipeshshihora\LogViewer\Services\LogParser as BaseParser;
class CustomLogParser extends BaseParser {
public function parseLine(string $line): array {
// Custom parsing logic
return $parsedData;
}
}
$this->app->bind(LogParser::class, CustomLogParser::class);
Adding Metadata:
// In a middleware or service
Log::withContext(['user_id' => auth()->id()])->error('Test error');
Export Functionality:
// In LogViewerController
public function export(Request $request) {
$logs = LogViewer::getLogs($request->all());
return response()->json($logs)->header('Content-Type', 'application/json');
}
Real-Time Updates:
// Public/js/app.js
Echo.channel('log-channel')
.listen('LogEvent', (e) => {
// Append new log to the UI
});
How can I help you explore Laravel packages today?