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

creative-syntax/laravel-logviewer

Web UI to view, filter, download, and delete Laravel log files. Includes per-level extraction, bulk/selected ZIP downloads, clear/delete actions, configurable route prefix/name and page heading, plus optional access restriction via config/.env authentication.

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Run:

    composer require creative-syntax/laravel-logviewer
    

    Publish the config (optional):

    php artisan vendor:publish --provider="CreativeSyntax\LogViewer\LogViewerServiceProvider"
    
  2. Basic Usage

    • Access logs via /logs route (default).
    • No additional setup required for default behavior.
  3. First Use Case

    • Debug an unexpected error by navigating to /logs and filtering by error level (e.g., error, critical).
    • Search for specific keywords (e.g., auth, database) to isolate relevant entries.

Implementation Patterns

Common Workflows

  1. Log Filtering

    • Use query parameters to filter logs:
      /logs?level=error&search=auth
      
    • Supported levels: debug, info, notice, warning, error, critical, alert, emergency.
  2. Customizing Log Display

    • Override the default view by publishing the view:
      php artisan vendor:publish --tag=logviewer.views
      
    • Modify resources/views/vendor/logviewer/logs.blade.php to add columns (e.g., context, extra).
  3. Integration with Existing Log Channels

    • Ensure your config/logging.php includes the channels you want to monitor (e.g., single, daily, slack).
    • The package reads from Laravel’s default log channels by default.
  4. Programmatic Access

    • Use the LogViewer facade to fetch logs programmatically:
      use CreativeSyntax\LogViewer\Facades\LogViewer;
      
      $logs = LogViewer::getLogs(['level' => 'error']);
      
  5. Middleware for Restricted Access

    • Protect the /logs route by adding middleware (e.g., auth or role:admin) in routes/web.php:
      Route::middleware(['auth'])->group(function () {
          Route::get('/logs', [LogViewerController::class, 'index']);
      });
      

Gotchas and Tips

Pitfalls

  1. Log File Permissions

    • Ensure Laravel’s log directory (storage/logs/) is writable by the web server user.
    • Debug permission issues with:
      chmod -R 775 storage/logs/
      
  2. Large Log Files

    • The package loads logs into memory. For files >10MB, consider:
      • Trimming older logs via Log::channel('single')->info('Custom log entry') with a maxFiles config.
      • Using tail to stream logs in real-time (not natively supported; may require customization).
  3. Custom Log Channels

    • If using non-default channels (e.g., monolog), ensure they are configured in config/logging.php and the package’s config/logviewer.php includes them:
      'channels' => ['single', 'daily', 'monolog'],
      
  4. Timezone Mismatches

    • Log timestamps may appear in UTC. Override the timezone in config/logviewer.php:
      'timezone' => 'America/New_York',
      

Debugging Tips

  • Check Config Values: Verify config/logviewer.php for unexpected behavior (e.g., disabled channels).
  • Clear Cache: After publishing views/config, run:
    php artisan config:clear
    php artisan view:clear
    
  • LogViewer Facade: Use LogViewer::getLogs() to debug programmatically before UI changes.

Extension Points

  1. Custom Log Formatting

    • Extend the LogEntry model (if available) or override the view to format logs (e.g., JSON pretty-printing).
  2. Add Log Actions

    • Extend the controller to add buttons (e.g., "Clear Logs"):
      // app/Http/Controllers/LogViewerController.php
      public function clearLogs()
      {
          $files = Storage::files(storage_path('logs'));
          foreach ($files as $file) {
              Storage::delete($file);
          }
          return back()->with('success', 'Logs cleared!');
      }
      
  3. Real-Time Updates

    • Integrate with Laravel Echo/Pusher to push new logs to the frontend (requires custom JS and backend logic).
  4. Export Functionality

    • Add endpoints 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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
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