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

Log Viewer Laravel Package

shaonmajumder/log-viewer

Beautiful, secure Laravel log viewer for Laravel 9–11 and PHP 8+. Auto-discovers log files, highlights levels, supports themes, search and level filtering, context expansion, tail mode, auto-refresh, and downloading full or filtered output.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require shaonmajumder/log-viewer
    

    Publish config and views:

    php artisan vendor:publish --tag=log-viewer-config
    php artisan vendor:publish --tag=log-viewer-views
    
  2. First Use Case Access /log-viewer in your browser. The package auto-detects Laravel log files (laravel.log, rotated logs) and displays them with color-coded levels (ERROR, WARNING, INFO, DEBUG).


Where to Look First

  • Config: config/log-viewer.php (adjust route_prefix, middleware, auth_required).
  • Routes: Defaults to /log-viewer (customizable via route_prefix).
  • Views: Override resources/views/vendor/log-viewer/index.blade.php for UI tweaks.

Implementation Patterns

Core Workflows

  1. Log Discovery The package automatically scans for:

    • laravel.log
    • Rotated logs (laravel-YYYY-MM-DD.log)
    • Custom paths (configure via log_paths in config).
  2. Filtering & Search Use the UI controls for:

    • Level filtering (ERROR/WARNING/INFO/DEBUG).
    • Full-text search (instant results).
    • Context expansion (e.g., ±5 lines around matches).
  3. Access Control

    • Default: Requires login (auth_required = true).
    • Custom: Use allowed_emails or a callback in authorize config.
    • Public Access: Set auth_required = false (e.g., for internal tools).
  4. Theming

    • Built-in dark themes (Dark Ink, Dark Graphite, Dark Forest).
    • User preference persists via localStorage.
  5. Download Logs

    • Download filtered logs or full logs via /log-viewer/download.

Integration Tips

  • Middleware: Add custom middleware to middleware in config (e.g., ['web', 'admin']).
  • Layout Overrides: Extend log-viewer::layouts.app for consistent branding.
  • Custom Auth: Use authorize callback for role-based access:
    'authorize' => function ($user) {
        return $user->isAdmin(); // Example
    }
    
  • Log Paths: Extend auto-discovery with log_paths:
    'log_paths' => [
        storage_path('logs/custom.log'),
    ],
    

Gotchas and Tips

Pitfalls

  1. Route Conflicts

    • Avoid naming collisions with host routes (e.g., laravel.log.*).
    • Fix: Use route_name_prefix (default: log.viewer.).
  2. Auth Bypass

    • If auth_required = true but users can’t log in, check:
      • Middleware (default: ['web']).
      • Custom auth logic in authorize callback.
  3. Log File Permissions

    • Ensure Laravel’s log directory (storage/logs) is readable by the web server.
  4. Large Logs

    • Tail mode (⏱️) may lag with >10K lines. Use limits (e.g., 1000 lines).

Debugging

  • No Logs Displaying?

    • Verify log_paths in config includes your log files.
    • Check file permissions (chmod -R 755 storage/logs).
  • Theme Not Saving?

    • Clear localStorage or check for JavaScript errors in browser console.
  • Download Fails?

    • Ensure storage_path('logs') is writable.

Extension Points

  1. Custom Highlighting Override highlightLogContent() in a service provider:

    LogViewer::extend(function ($content) {
        return preg_replace('/\bERROR\b/i', '<span class="custom-error">ERROR</span>', $content);
    });
    
  2. Add Log Sources Extend LaravelLogViewerServiceProvider to include non-Laravel logs:

    $this->app->bind('log-viewer.source', function () {
        return new CustomLogSource();
    });
    
  3. Modify UI Override resources/views/vendor/log-viewer/index.blade.php or extend the layout.

  4. Real-Time Updates Use Laravel Echo/Pusher to sync log changes across instances (advanced).


Config Quirks

  • auth_required vs Middleware:

    • Middleware runs first (e.g., auth middleware redirects guests).
    • auth_required is a secondary check (useful for custom logic).
  • allowed_emails:

    • Case-sensitive. Use [] to disable.
    • Example: ['admin@example.com'].
  • Theme Persistence:

    • Relies on localStorage. For SSO environments, consider server-side theme storage.

Pro Tips

  • Dev Environments: Set auth_required = false for quick access.
  • Production: Restrict with allowed_emails or authorize callback.
  • CI/CD: Exclude log files from backups (sensitive data).
  • Performance: For large logs, pre-process with tail -n 1000 in a cron job.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky