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 Good Log Viewer Laravel Package

golovchanskiy/laravel-good-log-viewer

LaravelGoodLogViewer is a simple log reader, parser, and viewer for Laravel 5. Install via Composer, register the service provider and facade, publish config/translations, then browse logs at /logs. Includes English and Russian locales.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:
    composer require golovchanskiy/laravel-good-log-viewer
    
  2. Register Provider & Facade: Add to config/app.php:
    'providers' => [
        // ...
        \Golovchanskiy\LaravelGoodLogViewer\GoodLogViewerServiceProvider::class,
    ],
    'aliases' => [
        // ...
        'GoodLogViewer' => \Golovchanskiy\LaravelGoodLogViewer\GoodLogViewer::class,
    ]
    
  3. Publish Assets:
    php artisan good-log-viewer:publish
    
  4. Access Logs: Visit /logs in your browser. No additional configuration is required for basic usage.

First Use Case

  • Debugging: Quickly inspect logs without manually tailing files.
  • Production Monitoring: Identify errors or unexpected behavior in real-time.
  • Team Collaboration: Share log snippets with non-technical stakeholders via the web interface.

Implementation Patterns

Core Workflows

  1. Log Parsing & Display:

    • The package automatically parses Laravel’s default log files (e.g., storage/logs/laravel.log) and renders them in a user-friendly format.
    • Example: Use the facade to fetch logs programmatically:
      $logs = GoodLogViewer::getLogs(100); // Fetch last 100 entries
      
  2. Custom Log File Integration:

    • Extend the package to support additional log files (e.g., storage/logs/custom.log):
      // In a service provider or config file:
      'log_files' => [
          storage_path('logs/laravel.log'),
          storage_path('logs/custom.log'),
      ],
      
    • Publish and update the config:
      php artisan config:clear
      
  3. Localization:

    • Switch between English (en) and Russian (ru) via the app config:
      'locale' => 'ru', // or 'en'
      
  4. API Access:

    • Fetch logs via an API endpoint (e.g., for frontend integration):
      Route::get('/api/logs', function () {
          return GoodLogViewer::getLogs(request('limit', 50));
      });
      

Integration Tips

  • Middleware: Restrict access to /logs in production:
    Route::middleware(['auth'])->group(function () {
        Route::get('/logs', [LogViewerController::class, 'index']);
    });
    
  • Logging Channels: Ensure your config/logging.php uses the default single channel for compatibility:
    'default' => env('LOG_CHANNEL', 'single'),
    
  • Queue Workers: If using queued log handlers (e.g., queue), ensure the package’s file watcher is configured to poll frequently enough.

Gotchas and Tips

Pitfalls

  1. File Permissions:

    • Ensure the web server user (e.g., www-data, nginx) has read access to storage/logs/.
    • Fix with:
      chmod -R 755 storage/logs/
      chown -R www-data:www-data storage/logs/
      
  2. Log Rotation:

    • If logs are rotated (e.g., via laravel-log-rotate), the package may not auto-detect new files. Manually add paths to config/good-log-viewer.php:
      'log_files' => [
          storage_path('logs/laravel-*.log'),
      ],
      
  3. Caching:

    • The package caches log entries for performance. Clear cache if logs aren’t updating:
      php artisan cache:clear
      
  4. Laravel Version:

    • The package is Laravel 5.x only. For Laravel 8/9/10, consider alternatives like spatie/laravel-log-viewer.

Debugging

  • Logs Not Showing:

    • Verify the log file exists at storage/logs/laravel.log.
    • Check the package’s config for correct paths.
    • Temporarily disable log rotation to test:
      'rotation' => [
          'enabled' => false,
      ],
      
  • Facade Not Found:

    • Ensure the alias is correctly registered in config/app.php and the service provider is loaded.

Extension Points

  1. Custom Log Formatters:

    • Override the LogEntry model to modify how logs are parsed:
      namespace App\Models;
      use Golovchanskiy\LaravelGoodLogViewer\Models\LogEntry as BaseLogEntry;
      
      class LogEntry extends BaseLogEntry {
          public function getMessageAttribute($value) {
              return "[Custom] " . parent::getMessageAttribute($value);
          }
      }
      
    • Bind the model in a service provider:
      $this->app->bind(
          \Golovchanskiy\LaravelGoodLogViewer\Models\LogEntry::class,
          App\Models\LogEntry::class
      );
      
  2. Add Filters:

    • Extend the LogFilter class to add custom search functionality:
      namespace App\Filters;
      use Golovchanskiy\LaravelGoodLogViewer\Filters\LogFilter as BaseLogFilter;
      
      class LogFilter extends BaseLogFilter {
          public function byLevel($level) {
              return $this->where('level', $level);
          }
      }
      
    • Update the config to use your filter:
      'filter_class' => App\Filters\LogFilter::class,
      
  3. Theming:

    • Override the Blade views in resources/views/vendor/good-log-viewer to customize the UI.

Pro Tips

  • Environment-Specific Routes:
    if (app()->environment('local')) {
        Route::get('/logs', [GoodLogViewerController::class, 'index']);
    }
    
  • Log Search:
    • Use the search parameter in the /logs route to filter logs:
      /logs?search=error
      
  • Performance:
    • For large log files, limit the number of entries fetched:
      'default_limit' => 1000, // in config/good-log-viewer.php
      
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.
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
anil/file-picker
broqit/fields-ai