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 View Php Laravel Package

jingyue/log-view-php

Laravel log viewer based on rap2hpoutre/laravel-log-viewer, with added navigation for logs stored in nested folders. Browse, search, and inspect Laravel/Lumen log files in your browser by routing to the controller—no public assets required.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require jingyue/log-view-php
    

    Ensure your composer.json includes the package under require.

  2. Publish Configuration (optional):

    php artisan vendor:publish --provider="Jingyue\LogViewer\LogViewerServiceProvider"
    

    This generates a config/log-viewer.php file for customization.

  3. Route Definition: Add this to your routes/web.php (or routes/api.php for Lumen):

    Route::get('/logs', 'Jingyue\LogViewer\LogViewerController@index');
    

    For Lumen, use:

    $router->get('/logs', 'Jingyue\LogViewer\LogViewerController@index');
    
  4. First Use Case: Visit /logs in your browser. The package will display a hierarchical view of Laravel’s log files (e.g., storage/logs/laravel.log, nested folders like storage/logs/debug/, etc.). Clicking a log file opens its contents with syntax highlighting.


Implementation Patterns

Core Workflows

  1. Log Navigation:

    • The package renders a tree view of log directories (e.g., laravel.log, debug/, job/) with collapsible folders.
    • Clicking a log file opens a code-like viewer with line numbers, timestamps, and log levels (e.g., INFO, ERROR) color-coded.
  2. Integration with Laravel’s Logging:

    • Works seamlessly with Laravel’s default Monolog setup. No changes to your config/logging.php are needed.
    • Supports single-file logs (e.g., laravel.log) and rotated logs (e.g., laravel-2023-10-01.log).
  3. Search Functionality:

    • Use the search bar to filter logs by content (e.g., type: Error, user: 123).
    • Supports regex patterns (e.g., /\d{3}-/) for advanced queries.
  4. Access Control:

    • Restrict access via middleware:
      Route::get('/logs', function () {
          if (auth()->check() && auth()->user()->isAdmin()) {
              return app('log-viewer')->show();
          }
          abort(403);
      });
      
  5. Customizing Log Paths: Override the default log path in config/log-viewer.php:

    'log_path' => storage_path('custom-logs'),
    

Advanced Patterns

  • Extending the Viewer: Add custom log files or directories by modifying the LogViewerServiceProvider:

    public function register()
    {
        $this->app->bind('log-viewer.paths', function () {
            return [
                storage_path('logs/laravel.log'),
                storage_path('custom-logs/'),
            ];
        });
    }
    
  • API Access: For programmatic log inspection, use the LogViewerFacade:

    use Jingyue\LogViewer\Facades\LogViewer;
    
    $logs = LogViewer::getLogs(); // Returns array of log entries
    
  • Lumen-Specific: In Lumen, inject the controller directly:

    $app->get('/logs', 'Jingyue\LogViewer\LogViewerController@index');
    

Gotchas and Tips

Pitfalls

  1. Permission Issues:

    • Ensure the web server user (e.g., www-data, nginx) has read access to storage/logs/.
    • Fix with:
      chmod -R 755 storage/logs/
      chown -R www-data:www-data storage/logs/
      
  2. Large Log Files:

    • The viewer may time out or crash with logs >10MB. Mitigate by:
      • Using config/logging.php to rotate logs daily.
      • Adding a max_lines filter in config/log-viewer.php:
        'max_lines' => 5000,
        
  3. Nested Folder Quirks:

    • The "enhancement" for nested folders may break if log files are symlinked. Verify paths in config/log-viewer.php.
  4. Caching:

    • The viewer does not cache log data. For high-traffic apps, consider:
      • Adding a Cache::remember layer around LogViewer::getLogs().
      • Using a queue to pre-process logs (e.g., LogViewer::processLogs()).
  5. Lumen Compatibility:

    • Lumen’s minimalist setup may require manual bootstrapping:
      $app->register(Jingyue\LogViewer\LogViewerServiceProvider::class);
      

Debugging Tips

  • Log Not Showing? Check if the route is registered and the controller is autoloaded. Run:

    php artisan route:list
    

    Ensure Jingyue\LogViewer\LogViewerController@index appears.

  • Blank Page? Enable Laravel’s debug mode (APP_DEBUG=true in .env) and check for:

    • Missing storage/logs/ directory (create it manually).
    • PHP errors in storage/logs/laravel.log.
  • Search Not Working? The search uses JavaScript (likely jQuery). Verify:

    • No JS errors in browser console.
    • The search endpoint is not blocked by CORS (unlikely for local dev).

Extension Points

  1. Custom Log Levels: Extend the LogLevel class to support your app’s custom levels:

    namespace App\Extensions;
    
    use Jingyue\LogViewer\LogLevel;
    
    class CustomLogLevel extends LogLevel
    {
        public static function getColors(): array
        {
            return array_merge(parent::getColors(), [
                'CUSTOM' => '#800080', // Purple for "CUSTOM" level
            ]);
        }
    }
    

    Then bind it in the service provider.

  2. Add Context to Logs: Parse log entries to extract structured data (e.g., user IDs, request IDs) and display them as clickable links. Example:

    // In a custom LogViewer extension
    $logEntry->context['user_id'] = preg_match('/user_id: (\d+)/', $entry, $matches) ? $matches[1] : null;
    
  3. Export Functionality: Add a download button to export logs as JSON/CSV:

    // In LogViewerController
    public function export()
    {
        $logs = LogViewer::getLogs();
        return response()->json($logs)->header('Content-Type', 'application/json');
    }
    
  4. Real-Time Updates: Use Laravel Echo/Pusher to push new log entries to the client:

    // Frontend JS
    Echo.channel('logs')
        .listen('LogUpdated', (e) => {
            // Append new log entry to the DOM
        });
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui