Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Log Viewer Laravel Package

achyutn/filament-log-viewer

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require achyutn/filament-log-viewer
    

    Publish the config (optional):

    php artisan vendor:publish --provider="Achyutn\FilamentLogViewer\FilamentLogViewerServiceProvider" --tag="config"
    
  2. Register the Plugin Add to app/Providers/Filament/AdminPanelProvider.php:

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \Achyutn\FilamentLogViewer\FilamentLogViewerPlugin::make(),
            ]);
    }
    
  3. First Use Case Access the plugin via the Filament admin panel (default path: /admin/log-viewer). Immediately view:

    • Log entries in a tabular format
    • Search/filter by log level, date, or content
    • Clickable stack traces (if available)

Where to Look First

  • Config File: config/filament-log-viewer.php (for log paths, retention, etc.)
  • Plugin Class: app/Providers/Filament/AdminPanelProvider.php (registration)
  • Default Log Path: storage/logs/laravel.log (configurable)

Implementation Patterns

Core Workflows

  1. 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'],
    ],
    
  2. 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.

  3. 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;
    }
    

Integration Tips

  • 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'],
            ],
        ];
    }
    

Gotchas and Tips

Pitfalls

  1. Log Rotation Conflicts

    • If using logrotate, ensure the plugin’s retention settings don’t overlap.
    • Fix: Disable retention in config if using external tools:
      'retention' => ['enabled' => false],
      
  2. Large Log Files

    • Performance degrades with files >10MB. Use log:clear or split logs.
    • Tip: Configure LOG_MAX_FILES in .env to limit file size.
  3. Stack Trace Parsing

    • Some log formats (e.g., JSON) may break stack trace rendering.
    • Workaround: Extend StackTraceRenderer to handle custom formats.

Debugging

  • 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
    

Extension Points

  1. 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'
            );
        });
    }
    
  2. Export Functionality Override the default export handler:

    public static function getExportHandler(): string
    {
        return \Achyutn\FilamentLogViewer\Exports\CustomLogExport::class;
    }
    
  3. 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
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope