Installation
Run composer require vietstars/logs-viewer in your Laravel 10 project.
Register the Service Provider
Add this to bootstrap/app.php:
$app->register(\Vietstars\LogsViewer\LogsViewerServiceProvider::class);
Define Routes
Add this to routes/web.php (or your preferred route file):
Route::get('logs', [\Vietstars\LogsViewer\Controllers\LogsViewerController::class, 'index'])->name('logs.viewer');
(Note: The README mentions app/Http/routes.php, but Laravel 10+ uses routes/web.php.)
Access Logs
Visit /logs in your browser to view Laravel’s log files.
/logs endpoint to inspect logs without tailing files manually.error, auth, 500).Development Workflow
/logs endpoint with teammates to debug issues collaboratively.Production Workflow
user_id:123).Integration with Monitoring
Customize the View Publish and modify the Blade template:
php artisan vendor:publish --provider="Vietstars\LogsViewer\LogsViewerServiceProvider" --tag=views
Extend Functionality
// app/Http/Controllers/LogsViewerController.php
public function index(Request $request) {
$logs = Log::query()->when($request->filled('method'), function($query) use ($request) {
return $query->where('context.method', $request->method);
})->get();
return view('logs-viewer::log', compact('logs'));
}
Authentication
Protect the route with middleware (e.g., auth, admin):
Route::get('/logs', [\Vietstars\LogsViewer\Controllers\LogsViewerController::class, 'index'])
->middleware('can:view-logs')
->name('logs.viewer');
Configuration Publish the config file for adjustments:
php artisan vendor:publish --provider="Vietstars\LogsViewer\LogsViewerServiceProvider"
log_file to customize the path (e.g., storage/logs/custom.log).per_page for pagination limits or max_lines to control log volume.Performance Overhead
max_lines in config to limit results.Log::channel('database'), ensure your database can handle the query load.Route Conflicts
/logs route may conflict with other packages. Rename it in routes/web.php:
Route::get('/admin/logs', [\Vietstars\LogsViewer\Controllers\LogsViewerController::class, 'index']);
Log File Permissions
www-data, nginx) has read access to the log file:
chmod 644 storage/logs/laravel.log
Real-Time Updates
setInterval).Log Not Showing?
config/logging.php matches the log_file in config/logviewer.php.ls -la storage/logs/
touch storage/logs/laravel.log
Blank Page?
php artisan view:clear
log.blade.php.Search Not Working
$logs = Log::query()->where('message', 'like', "%{$request->search}%")->get();
Custom Log Channels
Extend the controller to support multiple log channels (e.g., single, daily, slack):
public function index(Request $request) {
$channel = $request->input('channel', 'single');
$logs = Log::channel($channel)->query()->get();
return view('logs-viewer::log', compact('logs'));
}
Log Highlighting Use JavaScript to syntax-highlight log entries (e.g., JSON, stack traces):
// resources/js/logs-viewer.js
document.querySelectorAll('.log-entry').forEach(entry => {
entry.innerHTML = entry.textContent.replace(/({.*?})/g, '<span class="json">$1</span>');
});
Export Functionality Add a download button to export filtered logs as a JSON/CSV file:
// In LogsViewerController
public function export(Request $request) {
$logs = Log::query()->where('message', 'like', "%{$request->search}%")->get();
return response()->json($logs->toArray());
}
Log Retention
Integrate with Laravel’s log rotation (config/logging.php) to auto-clean old logs:
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 7, // Retain logs for 7 days
],
How can I help you explore Laravel packages today?