logviewerlaravel/log-viewer-laravel
Installation:
composer require logviewerlaravel/log-viewer-laravel
Add the following to routes/web.php:
Route::get('logs', [\LogViewerLaravel\LogViewerController::class, 'index'])->name('log.viewer');
Route::get('logs/logs_view', [\LogViewerLaravel\LogViewerController::class, 'view']);
First Use Case:
/logs in your browser to view Laravel’s default log file (storage/logs/laravel.log).Where to Look First:
routes/web.php./resources/views/vendor/laravel-log-viewer/ if customization is needed./config/logviewer.php (publish it first if needed) for log file paths, filters, or display settings.Basic Log Viewing:
/logs route for a quick, unfiltered view of logs.Customized Log Display:
php artisan vendor:publish --provider="ViewerLogic\LogViewerLaravelProvider" --tag=views
/resources/views/vendor/laravel-log-viewer/log.blade.php to:
error, info).Configuration Overrides:
php artisan vendor:publish --provider="ViewerLogic\LogViewerLaravelProvider"
/config/logviewer.php to:
'log_file' => storage_path('logs/custom-app.log'),
debug logs in production):
'levels' => ['error', 'warning', 'info'],
'per_page' => 100,
Integration with Laravel Features:
Route::get('logs', [LogViewerController::class, 'index'])->middleware('can:view-logs')->name('log.viewer');
event(new CustomLogEvent('User action triggered'));
Ensure the event’s toLog() method formats output compatibly with the viewer.API Access:
Route::get('logs/api', [LogViewerController::class, 'getLogsAsJson']);
Add this method to the controller to return parsed logs:
public function getLogsAsJson()
{
return response()->json($this->getLogs());
}
Log File Permissions:
www-data, nginx) has read access to storage/logs/laravel.log.chmod -R 755 storage/logs
chown -R www-data:www-data storage/logs
Large Log Files:
tail command or stream logs in chunks:
$logs = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
array_slice($logs, -1000); // Show last 1000 lines
Missing Published Files:
php artisan view:clear
Namespace Conflicts:
\ViewerLogic\LogViewerLaravelProvider and \LogViewerLaravel\LogViewerController.composer dump-autoload if routes fail.Log Rotation:
laravel-logger), the viewer may not auto-detect new files.$logFiles = glob(storage_path('logs/laravel*.log'));
Logs Not Showing:
storage/logs/laravel.log.config/logviewer.php:
'debug' => true,
This may log errors to storage/logs/laravel.log.Custom View Not Loading:
/resources/views/vendor/laravel-log-viewer/log.blade.php.Performance Issues:
Log::channel() to write logs to a dedicated file for the viewer:
Log::channel('custom')->info('Test log');
Then configure the viewer to use this channel’s log file.Environment-Specific Routes:
if (app()->environment('local')) {
Route::get('logs', [LogViewerController::class, 'index']);
}
Search Functionality:
public function index(Request $request)
{
$search = $request->query('search');
$logs = $this->filterLogs($search);
return view('vendor.laravel-log-viewer.log', ['logs' => $logs]);
}
Add a search input to the Blade view.Log Level Badges:
@foreach($logs as $log)
<div class="p-2 {{ $log['level'] === 'error' ? 'bg-red-100' : 'bg-gray-100' }}">
{{ $log['message'] }}
</div>
@endforeach
GitHub Actions Integration:
- name: View logs on failure
if: failure()
run: curl http://localhost:8000/logs
(Run the app locally in the pipeline with php artisan serve.)Extending for Multi-Tenant Apps:
public function __construct()
{
$this->logFile = storage_path("logs/tenant-{$this->tenant->id}.log");
}
How can I help you explore Laravel packages today?