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

danilovl/log-viewer-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require danilovl/log-viewer-bundle
    

    Add to config/bundles.php and run php bin/console assets:install.

  2. Basic Configuration: Create config/packages/danilovl_log_viewer.yaml with minimal settings:

    danilovl_log_viewer:
        sources:
            dirs: ['%kernel.logs_dir%']
        parser:
            go_enabled: false
    
  3. First Use Case: Access /danilovl/log-viewer to view logs in the dashboard. No additional setup is required for default behavior.


Implementation Patterns

Core Workflows

  1. Log Discovery & Filtering:

    • Configure sources.dirs to include log directories (e.g., %kernel.logs_dir%).
    • Use sources.ignore to exclude files (e.g., ['cache.log']).
    • Override parsers for specific files via parser.overrides:
      parser:
          overrides:
              '/var/log/nginx/error.log': 'nginx_error'
      
  2. Real-Time Monitoring: Enable live logs with:

    live_log_page:
        enabled: true
        interval: '3 sec'
        levels: ['error', 'critical']
    

    Access via /danilovl/log-viewer/live.

  3. Remote Logs: Add SSH/SFTP hosts:

    sources:
        remote_hosts:
            - name: 'prod_server'
              type: 'ssh'
              host: '1.2.3.4'
              user: 'deploy'
              ssh_key: '%kernel.project_dir%/config/ssh/id_rsa'
              dirs: ['/var/www/app/var/log']
    
  4. AI Integration: Configure AI chats for error logs:

    ai:
        button_levels: ['error', 'critical']
        chats:
            - { name: 'ChatGPT', url: 'https://chatgpt.com/?q={prompt}' }
    
  5. Notifications: Set up notifier rules and run the watcher:

    php bin/console danilovl:log-viewer:watch --interval=5
    

    Configure transports in framework.yaml (e.g., Slack/Telegram).


Integration Tips

  • Symfony Notifier: Ensure symfony/notifier is installed for notifications.
  • Go Parser: Enable for large files (go_enabled: true), but verify the binary path.
  • Vue 3 SPA: Customize the frontend by extending the Vue components in Resources/assets/js/.
  • API Usage: Leverage the REST API (prefix: /danilovl/log-viewer/api) for custom dashboards:
    // Example: Fetch log entries via API
    $response = $client->get('/danilovl/log-viewer/api/logs?file=/var/log/app.log');
    

Gotchas and Tips

Pitfalls

  1. Permissions:

    • Ensure log files are readable by the web server (e.g., chmod 644 /var/log/*.log).
    • For allow_delete/allow_download, files must be writable/readable by the web user.
  2. Go Parser:

    • Requires PHP 8.5+ and the Go binary (go_binary_path). Test locally before production.
    • If enabled but misconfigured, fall back to PHP parsing (slower for large files).
  3. Remote Hosts:

    • SSH/SFTP requires the ssh2 PHP extension. Install via:
      pecl install ssh2
      
    • Store SSH keys securely (e.g., in .env or encrypted config).
  4. Caching:

    • Disable cache.parser_detect_enabled if parser detection is unreliable.
    • Clear cache after config changes:
      php bin/console cache:clear
      
  5. Live Logs:

    • High interval values (e.g., 10 sec) may cause delays. Test with 3 sec for responsiveness.
    • Exclude verbose logs from live_log_page.levels to avoid noise.

Debugging

  • Log Parser Errors: Check var/log/dev.log for parser-related issues. Override parsers explicitly if needed.
  • Vue SPA Issues: Clear Encore assets:
    yarn build --watch
    
    Or rebuild:
    yarn build
    php bin/console assets:install
    
  • API Errors: Validate the api_prefix in config and ensure routes are loaded (_danilovl_log_viewer in routes.yaml).

Extension Points

  1. Custom Parsers: Extend the parser system by creating a new parser class and registering it in the bundle’s services:

    # config/services.yaml
    Danilovl\LogViewerBundle\Parser\CustomParser:
        tags: ['danilovl_log_viewer.parser']
    
  2. Frontend Customization: Override Vue components in templates/bundles/LogViewerBundle/ or extend via Encore:

    // assets/js/app.js
    import LogViewer from '@danilovl/log-viewer-bundle/js/components/LogViewer.vue';
    // Extend or replace components here
    
  3. Notifier Rules: Dynamically add rules via the API or CLI:

    php bin/console danilovl:log-viewer:notifier:add-rule --name="DB Errors" --levels="error" --channels="chat/slack"
    
  4. Dark/Light Mode: Force a theme via config:

    # config/packages/danilovl_log_viewer.yaml
    theme: 'dark'  # or 'light'
    

Performance Tips

  • Large Files: Use the Go parser (go_enabled: true) and set max_file_size to limit memory usage.
  • Live Logs: Reduce interval for critical logs (e.g., 1 sec) but increase for non-critical (e.g., 10 sec).
  • Statistics: Disable statistic_enabled if not needed to reduce CPU load.
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.
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
atriumphp/atrium