Installation
composer require achyutn/filament-log-viewer
Publish the config (optional):
php artisan vendor:publish --provider="Achyutn\FilamentLogViewer\FilamentLogViewerServiceProvider" --tag="config"
Register the Plugin
Add to app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Achyutn\FilamentLogViewer\FilamentLogViewerPlugin::make(),
]);
}
First Use Case
Access the plugin via the Filament admin panel (default path: /admin/log-viewer). Immediately view:
config/filament-log-viewer.php (for log paths, retention, etc.)app/Providers/Filament/AdminPanelProvider.php (registration)storage/logs/laravel.log (configurable)Log Filtering Use the built-in filters (dropdowns for log levels, date range picker) to narrow down entries:
// Customize filters in config:
'filters' => [
'levels' => ['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'],
'date_range' => ['last_24_hours', 'last_7_days', 'custom'],
],
Log Retention Management Automate log cleanup via config:
'retention' => [
'enabled' => true,
'days' => 30,
'command' => 'php artisan log:clear',
],
Trigger manually via Filament UI or CLI.
Stack Trace Handling Click any stack trace to expand/collapse details. Override the default renderer:
// In a custom plugin class:
public static function getStackTraceRenderer(): string
{
return \Achyutn\FilamentLogViewer\StackTraceRenderers\MonacoRenderer::class;
}
Custom Log Paths
Extend the LogViewer service to support non-standard log files:
$this->panel->plugins([
FilamentLogViewerPlugin::make()
->logPaths([storage_path('logs/custom.log'), storage_path('logs/api.log')]),
]);
Event Listeners Hook into log events to auto-refresh the viewer:
// In EventServiceProvider:
protected $listen = [
\Illuminate\Log\Events\MessageLogged::class => [
\Achyutn\FilamentLogViewer\Listeners\RefreshLogViewer::class,
],
];
Permissions Restrict access via Filament’s built-in policies:
public static function getPages(): array
{
return [
'log-viewer' => [
'label' => 'Logs',
'icon' => 'heroicon-o-document-text',
'permissions' => ['view-logs'],
],
];
}
Log Rotation Conflicts
logrotate, ensure the plugin’s retention settings don’t overlap.'retention' => ['enabled' => false],
Large Log Files
log:clear or split logs.LOG_MAX_FILES in .env to limit file size.Stack Trace Parsing
StackTraceRenderer to handle custom formats.Log Not Appearing?
Verify the log path in config/filament-log-viewer.php matches your LOG_CHANNEL in .env.
php artisan config:clear
Permission Denied Ensure the storage directory is writable:
chmod -R 775 storage/logs
Blank UI Check for JavaScript errors in browser console. Clear Filament cache:
php artisan filament:cache:clear
Custom Columns Add columns to the log table via a service provider:
public function boot()
{
FilamentLogViewer::extend(function (FilamentLogViewer $viewer) {
$viewer->addColumn(
fn ($record) => $record->context['user_id'] ?? 'N/A',
'User ID',
'user_id'
);
});
}
Export Functionality Override the default export handler:
public static function getExportHandler(): string
{
return \Achyutn\FilamentLogViewer\Exports\CustomLogExport::class;
}
Dark Mode Support Extend the plugin’s Tailwind classes:
// In resources/css/filament/filament-log-viewer.css
.dark .filament-log-viewer-table {
background: #1a1a1a;
}
Pro Tip: Use the log-viewer:tail Artisan command to stream logs in real-time during development:
php artisan log-viewer:tail --level=debug
How can I help you explore Laravel packages today?