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

srmilon/log-viewer

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:
    composer require srmilon/log-viewer
    
  2. Register Provider: Add Srmilon\LogViewer\LogServiceProvider::class to config/app.php under providers.
  3. Publish Views:
    php artisan vendor:publish --provider="Srmilon\LogViewer\LogServiceProvider" --tag=views
    
  4. Add Route: In routes/web.php, add:
    Route::get('/log', '\Srmilon\LogViewer\LogViewerController@index');
    
  5. Access Logs: Visit /log in your browser to view Laravel logs in detail.

First Use Case

  • Debugging: Quickly inspect logs during development without manually tailing log files.
  • Production Inspection: Safely view logs in a structured UI (if access is restricted to trusted users).

Implementation Patterns

Workflows

  1. Development Workflow:

    • Use /log as a live dashboard to monitor application behavior.
    • Filter logs by date, level (e.g., error, info), or keyword.
    • Example: Search for SQLSTATE[HY000] to debug database issues.
  2. Production Workflow:

    • Restrict access via middleware (e.g., auth or role checks).
    • Log critical errors to a separate file (e.g., storage/logs/errors.log) and exclude them from the viewer for security.
  3. Integration with Monitoring:

    • Combine with tools like Laravel Horizon or Sentry for deeper insights.
    • Example: Use the viewer to triage issues before forwarding to Sentry.

Customization

  • Override Views: Publish and modify the resources/views/vendor/log-viewer templates to match your app’s design.
  • Extend Functionality: Add custom log levels or filters by extending the LogViewerController or creating a middleware to pre-process logs.

Security

  • Route Protection:
    Route::get('/log', function () {
        if (!auth()->check() || !auth()->user()->isAdmin()) {
            abort(403);
        }
        return app(\Srmilon\LogViewer\LogViewerController::class)->index();
    });
    
  • Log File Permissions: Ensure storage/logs/ is readable only by the web server user (e.g., chmod 640 storage/logs/*).

Gotchas and Tips

Pitfalls

  1. Outdated Code:

    • The package was last updated in 2018 and requires PHP 5.3+. Test thoroughly in your environment (e.g., PHP 8.x may need polyfills).
    • Example: Use composer require nikic/php-parser if syntax errors arise due to PHP version mismatches.
  2. Performance Impact:

    • Loading all logs at once can be slow for large applications. Limit the number of logs displayed:
      // In LogViewerController, override the query to fetch recent logs only
      $logs = Log::query()->latest()->take(1000)->get();
      
  3. Log File Rotation:

    • If logs are rotated (e.g., via laravel-log-rotate), the viewer may not show recent logs. Ensure the package reads the correct log file (default: storage/logs/laravel.log).
  4. Missing Dependencies:

    • The package assumes Laravel’s default logging setup. If using a custom logger (e.g., Monolog with a different handler), the viewer may not display logs correctly.

Debugging

  • Logs Not Showing?:

    • Verify the log file path in config/logging.php matches the package’s expectations.
    • Check file permissions: ls -la storage/logs/.
    • Enable debug mode in config/app.php to see errors: 'debug' => env('APP_DEBUG', true).
  • Blank Page:

    • Clear cached views: php artisan view:clear.
    • Check for PHP errors in storage/logs/laravel.log.

Tips

  1. Filtering:

    • Add a search bar to the published view to filter logs by keyword (e.g., using JavaScript or Laravel Collective HTML).
    • Example:
      // In the published view, add:
      <input type="text" id="log-search" onkeyup="filterLogs()">
      
  2. Log Level Highlighting:

    • Use CSS to highlight log levels (e.g., red for error, green for info):
      .log-error { color: red; }
      .log-info { color: green; }
      
  3. Export Logs:

    • Add a button to export logs as a JSON/CSV file:
      Route::get('/log/export', function () {
          return response()->json(Log::all()->toArray());
      });
      
  4. Environment-Specific Routes:

    • Use environment variables to disable the route in production:
      if (app()->environment('local')) {
          Route::get('/log', '\Srmilon\LogViewer\LogViewerController@index');
      }
      
  5. Alternative for Modern Laravel:

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.
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
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