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

Lumen Log Viewer Laravel Package

maxsky/lumen-log-viewer

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require maxsky/lumen-log-viewer
    
  2. Register Service Provider in bootstrap/app.php (Lumen 8+):

    $app->register(\LumenLogViewer\Providers\LumenLogViewerServiceProvider::class);
    

    (For Lumen 5.x, use app/Providers/AppServiceProvider.php as per the README.)

  3. Add Route in routes/web.php:

    $router->get('logs', '\LumenLogViewer\Controllers\LogViewerController@index');
    
  4. Access Logs: Visit /logs (or your custom route) to view formatted logs in a simple UI.

First Use Case

  • Debugging: Quickly inspect logs during development without manually tailing files.
  • Error Tracing: Identify and analyze errors in real-time via the web interface.

Implementation Patterns

Core Workflow

  1. Log Integration:

    • The package automatically reads Lumen’s default log files (e.g., storage/logs/lumen.log).
    • No additional configuration is needed for standard Monolog setups.
  2. Customization:

    • Views: Override the default Blade template by copying vendor/maxsky/lumen-log-viewer/views/logviewer.blade.php to resources/views/vendor/lumen-log-viewer/logviewer.blade.php. Example modification:
      <pre>{{ print_r($logs, true) }}</pre> <!-- Replace with custom rendering -->
      
    • Routes: Extend the route group for namespacing or middleware:
      $router->group(['middleware' => 'auth'], function () use ($router) {
          $router->get('logs', 'LogViewerController@index');
      });
      
  3. Log Filtering:

    • The controller (LogViewerController) fetches logs via LogViewerService. Extend the service to add filters:
      // In a custom service provider
      $this->app->bind('LumenLogViewer\Services\LogViewerService', function ($app) {
          return new CustomLogViewerService($app['log']);
      });
      
  4. Security:

    • Restrict access to the /logs endpoint using middleware (e.g., auth or admin checks).

Advanced Patterns

  • Log Rotation Handling:
    • If logs are rotated (e.g., daily), ensure the package’s file reader handles multiple log files. Extend the LogViewerService to merge rotated logs:
      public function getLogs()
      {
          $logs = [];
          foreach (glob(storage_path('logs/lumen*.log')) as $file) {
              $logs = array_merge($logs, $this->readLogFile($file));
          }
          return $logs;
      }
      
  • Real-Time Updates:
    • Use Laravel Echo/Pusher to push new log entries to the frontend in real-time (requires custom frontend JS).

Gotchas and Tips

Pitfalls

  1. Lumen Version Mismatch:

    • The package is designed for Lumen 5.x. For Lumen 8+, ensure compatibility by:
      • Checking for deprecated methods (e.g., $this->app->register() vs. $app->register()).
      • Overriding the service provider if autowiring fails.
  2. Log File Permissions:

    • Ensure the web server user (e.g., www-data) has read access to storage/logs/. Run:
      chmod -R 755 storage/logs/
      
  3. Missing Logs:

    • If logs don’t appear, verify:
      • Monolog is configured to write to storage/logs/lumen.log (check bootstrap/app.php).
      • The log file exists and isn’t empty.
  4. Blade Template Caching:

    • Clear cached views if customizations aren’t reflected:
      php artisan view:clear
      

Debugging Tips

  1. Log the Logs:

    • Temporarily dump the raw logs in the controller to debug:
      dd($this->logViewerService->getLogs());
      
  2. Check Service Binding:

    • Ensure the LogViewerService is bound correctly. Add this to AppServiceProvider:
      $this->app->singleton('LumenLogViewer\Services\LogViewerService', function ($app) {
          return new \LumenLogViewer\Services\LogViewerService($app['log']);
      });
      
  3. Route Debugging:

    • Verify the route is registered and accessible:
      php artisan route:list
      

Extension Points

  1. Custom Log Sources:

    • Extend the service to support non-Monolog log sources (e.g., database logs):
      public function getLogs()
      {
          return DB::table('logs')->get()->toArray();
      }
      
  2. Log Formatting:

    • Modify the Blade template to highlight errors or add collapsible sections:
      @foreach($logs as $log)
          <div class="log-entry {{ $log['level'] === 'ERROR' ? 'error' : '' }}">
              {{ $log['message'] }}
          </div>
      @endforeach
      
  3. API Endpoint:

    • Convert the route to a JSON API for machine-readable logs:
      $router->get('logs/api', 'LogViewerController@api');
      
      Update the controller:
      public function api()
      {
          return response()->json($this->logViewerService->getLogs());
      }
      
  4. Search Functionality:

    • Add a search parameter to the route and filter logs in the service:
      public function index(Request $request)
      {
          $search = $request->input('search');
          $logs = $this->logViewerService->getLogs($search);
          return view('vendor.lumen-log-viewer.logviewer', compact('logs'));
      }
      
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.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky