netojose/laravel-log-viewer

A Laravel package for viewing and managing application log files.

Maintainers

Package info

github.com/netojose/laravel-log-viewer

Language:Blade

pkg:composer/netojose/laravel-log-viewer

Statistics

Installs: 34

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0 2026-04-15 09:13 UTC

This package is auto-updated.

Last update: 2026-04-15 09:17:47 UTC


README

A Laravel 11+ package for viewing, filtering, downloading and clearing application log files — directly in the browser.

image

Features

  • View and parse storage/logs/laravel.log (and additional log files)
  • Filter entries by log level (EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG)
  • Pagination for large log files
  • Download any log file
  • Clear (truncate) any log file
  • Route protection via Laravel Gate
  • Pure HTML/CSS UI — zero JavaScript/CSS framework dependencies
  • Publishable config and views

Requirements

  • PHP ^8.2
  • Laravel ^11.0 || ^12.0 || ^13.0

Installation

composer require netojose/laravel-log-viewer

The service provider is registered automatically via Laravel's package auto-discovery.

Publish the config (optional)

php artisan vendor:publish --tag=log-viewer-config

This copies config/log-viewer.php to your application's config directory.

Publish the views (optional)

php artisan vendor:publish --tag=log-viewer-views

Usage

After installation, visit:

http://your-app.test/log-viewer

Configuration

// config/log-viewer.php

return [

    // Enable or disable the log viewer entirely
    'enabled' => env('LOG_VIEWER_ENABLED', true),

    // URL prefix for all routes
    'prefix' => env('LOG_VIEWER_PREFIX', 'log-viewer'),

    // Middleware applied to all routes (authorization middleware is appended automatically)
    'middleware' => ['web'],

    // Gate name used for authorization (set to null to disable)
    'gate' => 'viewLogViewer',

    // Extra log files to expose (storage/logs/laravel.log is always included)
    'logs' => [
        // 'Worker'    => storage_path('logs/worker.log'),
        // 'Scheduler' => storage_path('logs/scheduler.log'),
    ],

    // Entries per page
    'per_page' => env('LOG_VIEWER_PER_PAGE', 50),

];

Authorization

By default, the viewLogViewer gate allows access only in the local environment. In any other environment (staging, production) access is denied with a 403.

To customize access, define the gate in your AppServiceProvider (or any service provider):

use Illuminate\Support\Facades\Gate;

public function boot(): void
{
    Gate::define('viewLogViewer', function ($user) {
        return in_array($user->email, [
            'admin@example.com',
        ]);
    });
}

To allow access for guests (unauthenticated users), accept a nullable user:

Gate::define('viewLogViewer', function (?User $user) {
    // custom logic
    return true;
});

To disable gate checks entirely, set 'gate' => null in your config.

Adding extra log files

Any entry in the logs config key becomes available in the log viewer:

'logs' => [
    'Worker'    => storage_path('logs/worker.log'),
    'Scheduler' => storage_path('logs/scheduler.log'),
    'Nginx'     => '/var/log/nginx/error.log',
],

Security note: Only files explicitly listed in the config can be accessed. User input is never used to derive file paths.

Available Routes

Method URI Name Description
GET /log-viewer log-viewer.index List all log files
GET /log-viewer/{file} log-viewer.show View log entries (?level=ERROR&page=2)
GET /log-viewer/{file}/download log-viewer.download Download log file
DELETE /log-viewer/{file} log-viewer.destroy Clear (truncate) log file

Disabling the package

Set the environment variable:

LOG_VIEWER_ENABLED=false

Routes will not be registered and the viewer will return 404.

License

MIT