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

sn0rk64/laravel-log-viewer

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require sn0rk64/laravel-log-viewer
    

    (Note: The package is a fork of rap2hpoutre/laravel-log-viewer; ensure you’re using the correct namespace in your code.)

  2. Register Service Provider (Laravel): Add to config/app.php:

    Sn0rk64\LaravelLogViewer\LaravelLogViewerServiceProvider::class,
    
  3. Add Route (Laravel): In routes/web.php:

    Route::get('logs', '\Sn0rk64\LaravelLogViewer\LogViewerController@index');
    
  4. Access Logs: Visit /logs in your browser. The viewer will display logs from storage/logs/laravel.log by default.

First Use Case

  • Debugging live issues: Quickly filter logs by level (e.g., error, warning) to isolate problems.
  • JSON inspection: Pretty-print JSON log entries for easy debugging of API responses or payloads.

Implementation Patterns

Core Workflows

  1. Log Filtering: Use the built-in log level filters (e.g., debug, info, error) to narrow down logs. Example URL:

    /logs?level=error
    

    (Supports multiple levels via comma-separated values: ?level=error,warning.)

  2. JSON Logs: The package automatically formats JSON log entries for readability. No manual parsing required.

  3. Lumen Support: Follow the Lumen-specific setup in the README (namespace grouping in bootstrap/app.php and routes.php).

Integration Tips

  • Custom Log Paths: Override the default log path by publishing the config:

    php artisan vendor:publish --provider="Sn0rk64\LaravelLogViewer\LaravelLogViewerServiceProvider" --tag="config"
    

    Then modify config/log-viewer.php to set log_file.

  • Middleware Protection: Restrict access to logs in production by wrapping the route in middleware:

    Route::get('logs', function () {
        if (app()->environment('production')) {
            abort(403);
        }
        return \Sn0rk64\LaravelLogViewer\LogViewerController::index();
    });
    
  • Log Rotation Compatibility: Works seamlessly with Laravel’s log rotation (e.g., laravel.log.2023_01_01). No additional setup needed.

  • Custom Views: Publish the view files for modification:

    php artisan vendor:publish --provider="Sn0rk64\LaravelLogViewer\LaravelLogViewerServiceProvider" --tag="views"
    

    Override resources/views/vendor/log-viewer/index.blade.php to add custom UI elements (e.g., timestamps, user context).


Gotchas and Tips

Pitfalls

  1. Namespace Mismatch: The package uses Sn0rk64\LaravelLogViewer (not Rap2hpoutre). Ensure all routes/controllers reference the correct namespace. Fix: Update routes and service provider registration to match the forked package.

  2. Log File Permissions: If logs fail to load, verify the web server user (e.g., www-data) has read access to storage/logs/. Fix: Run:

    chmod -R 755 storage/logs/
    chown -R www-data:www-data storage/logs/
    
  3. JSON Parsing Errors: Malformed JSON in logs may break the pretty-printing. The package silently skips invalid entries. Debug: Check raw logs via tail -f storage/logs/laravel.log for syntax issues.

  4. Route Cache Conflicts: After changing routes, clear the route cache:

    php artisan route:clear
    

Debugging Tips

  • Log Level Filtering: Use ?level=* to show all logs (default) or ?level=debug,info for specific levels. Debug logs are hidden by default in production.

  • Log Truncation: The viewer loads logs in chunks (configurable via config/log-viewer.php). Adjust max_lines to control pagination.

  • Custom Log Channels: To view logs from non-default channels (e.g., single or daily), extend the LogViewerController:

    use Monolog\Logger;
    public function index() {
        $logs = Logger::getMonolog()->channels['custom_channel']->getLogs();
        // Custom logic to render logs
    }
    

Extension Points

  1. Add Log Context: Extend the view to include request context (e.g., user ID, IP) by modifying the published blade template:

    @if(request()->user())
        <div class="context">User: {{ request()->user()->name }}</div>
    @endif
    
  2. Log Search: Implement a search feature by overriding the controller’s index() method to filter logs by keyword:

    public function index() {
        $search = request('search');
        $logs = collect($this->getLogs())
            ->filter(fn($log) => $search && stripos($log['message'], $search) !== false);
        return view('log-viewer::index', ['logs' => $logs]);
    }
    
  3. Log Export: Add a download button to export logs as JSON:

    Route::get('logs/export', [LogViewerController::class, 'export']);
    

    In the controller:

    public function export() {
        return response()->json($this->getLogs());
    }
    
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