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

gboquizosanchez/filament-log-viewer

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require gboquizosanchez/filament-log-viewer
    

    Publish the config file:

    php artisan vendor:publish --provider="Gboquizosanchez\FilamentLogViewer\FilamentLogViewerServiceProvider" --tag="filament-log-viewer-config"
    
  2. Register the Plugin Add to your PanelProvider (e.g., App\Providers/Filament/AdminPanelProvider):

    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                \Gboquizosanchez\FilamentLogViewer\FilamentLogViewerPlugin::make(),
            ]);
    }
    
  3. First Use Case Access the log viewer via the Filament sidebar (default location: Logs under the main menu). Immediately inspect recent log entries, filter by severity (e.g., error, warning), and search for specific keywords.


Implementation Patterns

Core Workflows

  1. Log Filtering & Search

    • Use the built-in date range picker to narrow logs to specific timeframes (e.g., last 24 hours).
    • Filter by log levels (e.g., debug, info, error) via dropdown or checkboxes.
    • Search bar supports regex (enable via config: enable_regex_search = true).
  2. Log Inspection

    • Click any log entry to expand it and view:
      • Full context (including stack traces).
      • Copy button for raw log content.
      • Collapsible sections for nested data (e.g., exceptions).
    • Dark mode support: Automatically adapts to Filament’s theme.
  3. Log Management

    • Clear logs: Use the bulk action to delete selected entries (configurable retention via log_max_files).
    • Download logs: Export filtered logs as .txt or .json (customize via download_format in config).
  4. Integration with Filament Features

    • Notifications: Trigger alerts when critical logs (e.g., error) appear (extend via LogViewerService events).
    • Permissions: Restrict access via Filament’s built-in policies:
      FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
          $plugin->canViewLogs(fn (User $user) => $user->isAdmin());
      });
      
  5. Custom Log Sources

    • Extend to monitor custom log channels (e.g., single or stack channels):
      FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
          $plugin->logChannels(['single', 'stack', 'custom_channel']);
      });
      

Advanced Patterns

  1. Log Highlighting Customize syntax highlighting for log entries via config:

    'highlighting' => [
        'error' => '#ff6b6b', // Custom color for errors
        'stack_trace' => true, // Enable stack trace syntax highlighting
    ],
    
  2. Log Retention Automatically purge old logs using Laravel’s Log::clean() or override via:

    FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
        $plugin->logMaxFiles(5); // Keep only 5 log files
    });
    
  3. Event Listeners Hook into log events to add metadata or modify entries:

    public function boot()
    {
        \Gboquizosanchez\FilamentLogViewer\Events\LogEntryCreated::listen(function ($entry) {
            $entry->context['custom_key'] = 'value';
        });
    }
    
  4. Localization Translate UI strings (e.g., "Clear Selected") via Filament’s localization system:

    FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
        $plugin->translationPrefix('filament-log-viewer');
    });
    

Gotchas and Tips

Pitfalls

  1. Performance with Large Logs

    • Issue: Slow rendering if logs exceed 10,000 entries.
    • Fix: Limit log retention or use log_max_files to cap stored files:
      'log_max_files' => 3, // Keep only 3 log files (~1 week for daily logs)
      
  2. Stack Trace Parsing

    • Issue: Stack traces may not render correctly for custom exceptions.
    • Fix: Extend the LogEntry model or override the formatStackTrace() method in the service provider.
  3. Permission Conflicts

    • Issue: Log viewer appears to all users despite policy restrictions.
    • Fix: Ensure policies are applied in configureUsing() after plugin registration.
  4. Config Overrides

    • Issue: Config changes not reflected after publishing.
    • Fix: Clear cached config:
      php artisan config:clear
      
  5. Dark Mode Glitches

    • Issue: Log entries appear unreadable in dark mode.
    • Fix: Override CSS via Filament’s styles directory or adjust highlighting colors.

Debugging Tips

  1. Log Entry Not Showing?

    • Verify the log channel is included in logChannels config.
    • Check if the log file exists in storage/logs/ and is readable by the web server.
  2. Stack Trace Truncated

    • Increase stack_trace_max_lines in config (default: 50).
  3. Search Not Working

    • Ensure enable_regex_search is false if using simple keyword searches (regex can be resource-intensive).
  4. Plugin Not Loading

    • Check for conflicts with other Filament plugins. Disable plugins one by one to isolate the issue.
    • Verify the service provider is registered in config/filament.php under panel_providers.

Extension Points

  1. Custom Log Formatter Override the default log entry formatting by binding a custom formatter:

    $this->app->bind(
        \Gboquizosanchez\FilamentLogViewer\Contracts\LogEntryFormatter::class,
        \App\Services\CustomLogFormatter::class
    );
    
  2. Add Log Actions Extend the log entry actions (e.g., "Replay Exception"):

    FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
        $plugin->registerAction(
            \Gboquizosanchez\FilamentLogViewer\Actions\ReplayException::make()
        );
    });
    
  3. Log Entry Metadata Inject additional data into log entries via middleware or service provider:

    \Gboquizosanchez\FilamentLogViewer\Events\LogEntryCreated::listen(function ($entry) {
        $entry->context['user_id'] = auth()->id();
    });
    
  4. Custom Log Storage Use a database-backed log system (e.g., spatie/laravel-log) by extending the LogViewerService:

    public function getLogs(): array
    {
        return \App\Models\StoredLog::query()->get()->toArray();
    }
    
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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver