composer require nmfmcosta/laravel-log-viewer
config/app.php under providers:
LB\LaravelLogViewer\LaravelLogViewerServiceProvider::class,
routes/web.php:
Route::get('logs', '\LB\LaravelLogViewer\LogViewerController@index');
/logs in your browser to view Laravel’s default log file (storage/logs/laravel.log).error, critical) to isolate issues in staging/production.Log Filtering:
level: debug, info, warning, error, critical.date: ?date=2024-01-01 (format: YYYY-MM-DD).search: Full-text search (e.g., ?search=authentication)./logs?level=error&date=2024-01-01
Integration with Laravel Debugbar:
Debugbar::addMenu('Logs', [
'link' => route('logs'),
'text' => 'View Logs',
]);
Custom Log Files:
storage/logs/custom.log):
php artisan vendor:publish --tag=config) and update logviewer.php:
'files' => [
storage_path('logs/laravel.log'),
storage_path('logs/custom.log'),
],
API Access (Lumen/Laravel):
Route::get('api/logs', '\LB\LaravelLogViewer\LogViewerController@apiIndex');
apiIndex method in the controller to return JSON:
public function apiIndex() {
return response()->json($this->getLogs());
}
Log Anonymization:
LogViewerController to sanitize sensitive data (e.g., passwords, tokens) before rendering:
protected function formatLogEntry($entry) {
$entry['message'] = str_replace('password=.*?&', 'password=***&', $entry['message']);
return $entry;
}
Log Retention:
logviewer.php to limit displayed logs (e.g., last 7 days):
'max_days' => 7,
Real-Time Updates:
Permission Issues:
www-data, nginx) has read access to storage/logs/:
chmod -R 755 storage/logs/
chown -R www-data:www-data storage/logs/
Large Log Files:
max_days in config to limit scope:
'max_days' => 30,
Route Conflicts:
/logs if it clashes with existing routes. Use a subpath like /admin/logs.Lumen Namespace:
namespace in bootstrap/app.php matches the route definition exactly to avoid ClassNotFound errors.Blank Page?:
logviewer.php config file exists in /config/. Publish it if missing:
php artisan vendor:publish --tag=config
files array includes the correct log path.Search Not Working:
?search=Error (not error) for consistency with log levels.Logs Not Updating:
log.blade.php aren’t reflected:
php artisan view:clear
Custom Styling:
resources/views/vendor/laravel-log-viewer/log.blade.php) to match your app’s design:
<style>
.log-entry.error { background: #ffebee; }
.log-entry.debug { font-style: italic; }
</style>
Environment-Specific Routes:
local environments in routes/web.php:
if (app()->environment('local')) {
Route::get('logs', '\LB\LaravelLogViewer\LogViewerController@index');
}
Log Level Aliases:
/logs?level=e # Equivalent to ?level=error
logviewer.php:
'level_aliases' => [
'e' => 'error',
'c' => 'critical',
],
Log Context:
Log::debug('User action', ['user_id' => auth()->id(), 'request_id' => request()->header('X-Request-ID')]);
Backup Logs:
logviewer.php:
'exclude_patterns' => [
'password',
'api_token',
'secret_',
],
How can I help you explore Laravel packages today?