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

Laravel Logviewer Laravel Package

endanguyen/laravel-logviewer

Laravel 5/4.2 and Lumen log viewer. Install via Composer, register the service provider, and add a route to LogViewerController to browse local log files in the browser. No public assets or vendor routes; works with and without log rotation.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require endanguyen/laravel-logviewer
    

    Publish the config (optional):

    php artisan vendor:publish --provider="Endanguyen\LogViewer\LogViewerServiceProvider"
    
  2. Register the Route Add this to routes/web.php (or routes.php for Lumen):

    Route::get('/logs', 'LogViewerController@index');
    

    Or use the helper:

    \LogViewer::routes();
    
  3. First Use Case Visit /logs in your browser. The package will:

    • Auto-detect Laravel’s default log file (storage/logs/laravel.log).
    • Display logs in reverse chronological order (newest first).
    • Support filtering by log level (e.g., error, info).

Implementation Patterns

Core Workflows

  1. Log Filtering

    • URL Parameters: Append ?level=error to filter logs by severity.
    • Custom Levels: Extend the LogViewer facade to support custom log channels:
      LogViewer::addChannel('custom', 'path/to/custom.log');
      
  2. Integration with Existing Log Channels

    • The package works out-of-the-box with Laravel’s default single channel. For multi-channel setups (e.g., stack or channels config), manually register channels in config/logviewer.php:
      'channels' => [
          'single' => storage_path('logs/laravel.log'),
          'slack'  => storage_path('logs/slack.log'),
      ],
      
  3. Middleware Integration

    • Restrict access to logs in production:
      Route::get('/logs', 'LogViewerController@index')->middleware('can:view-logs');
      
  4. Customizing the View

    • Override the default blade template by publishing assets:
      php artisan vendor:publish --tag=logviewer.views
      
    • Modify resources/views/vendor/logviewer/index.blade.php to add features like:
      • Syntax highlighting for log messages.
      • Copy-to-clipboard buttons for individual log entries.
  5. Programmatic Access

    • Fetch logs via the facade for CLI tools or APIs:
      $logs = LogViewer::getLogs(['level' => 'error', 'limit' => 100]);
      

Gotchas and Tips

Pitfalls

  1. Log Rotation Conflicts

    • If using logrotate, the viewer may show truncated logs. Solution: Configure logviewer.php to include rotated logs:
      'include_rotated' => true,
      
    • Or manually specify paths to rotated logs in the channels array.
  2. Permission Issues

    • Ensure the web server user (e.g., www-data) has read access to storage/logs/:
      chmod -R 755 storage/logs/
      chown -R www-data:www-data storage/logs/
      
  3. Large Log Files

    • Performance degrades with files >100MB. Mitigation:
      • Limit displayed logs via config/logviewer.php:
        'max_log_size' => 50, // MB
        
      • Use ?limit=500 in the URL to paginate results.
  4. Lumen Compatibility

    • Lumen lacks a default Log facade. Workaround: Manually bind the facade in bootstrap/app.php:
      $app->bind('log', function () {
          return new \Illuminate\Support\Facades\Log;
      });
      

Debugging Tips

  1. Verify Log Paths Check config/logviewer.php for correct paths. Use LogViewer::getChannels() to debug:

    dd(LogViewer::getChannels());
    
  2. Clear Cache After config changes, clear Laravel’s cache:

    php artisan config:clear
    php artisan view:clear
    
  3. Log Level Case Sensitivity Filtering is case-insensitive, but ensure consistency in config:

    // Valid:
    ?level=ERROR
    ?level=error
    

Extension Points

  1. Custom Log Parsers Extend the LogEntry model to parse structured logs (e.g., JSON):

    namespace Endanguyen\LogViewer;
    
    class CustomLogEntry extends LogEntry
    {
        public function parseMessage($message)
        {
            return json_decode($message, true);
        }
    }
    

    Register the custom parser in LogViewerServiceProvider.

  2. Add Search Functionality Override the controller to support search:

    public function index(Request $request)
    {
        $query = $request->input('q');
        $logs = LogViewer::searchLogs($query, $request->all());
        return view('vendor.logviewer.index', compact('logs'));
    }
    
  3. Export Logs Add a route to export logs as JSON/CSV:

    Route::get('/logs/export', function () {
        return response()->json(LogViewer::getLogs())->header('Content-Type', 'application/json');
    });
    
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony