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

devoralive/log-viewer-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require devoralive/log-viewer-bundle
    

    Ensure your composer.json includes the package under require.

  2. Enable the Bundle Add to config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):

    Devoralive\LogViewerBundle\LogViewerBundle::class => ['all' => true],
    
  3. Route Configuration Add to config/routes.yaml (Symfony 4+) or app/config/routing.yml (Symfony 3):

    log_viewer:
        resource: "@LogViewerBundle/Resources/config/routing.yml"
        prefix: /_logs
    
  4. First Use Case Access logs via browser:

    • Dev logs: http://your-app.local/_logs/_dev
    • Prod logs: http://your-app.local/_logs/_prod

Implementation Patterns

Core Workflows

  1. Log Inspection in Development

    • Use the /_logs/_dev endpoint to debug issues by inspecting raw Monolog JSON output.
    • Filter logs by time, level (e.g., ERROR, DEBUG), or channel (e.g., doctrine, security).
  2. Integration with Debug Toolbar

    • Add a custom toolbar link to /_logs/_dev for quick access during development:
      // src/Kernel.php (Symfony 4+)
      public function registerContainerConfiguration(LoaderInterface $loader)
      {
          $loader->load(function (ContainerBuilder $container) {
              $container->loadFromExtension('log_viewer', [
                  'toolbar' => true,
              ]);
          });
      }
      
  3. Conditional Log Exposure

    • Restrict access to logs in non-production environments:
      # config/packages/log_viewer.yaml
      log_viewer:
          enabled: '%kernel.environment% != "prod"'
      
  4. Custom Log Channels

    • Override the default log paths in config/packages/log_viewer.yaml:
      log_viewer:
          logs:
              custom_channel: '%kernel.logs_dir%/custom.log'
      
    • Access via /_logs/_custom_channel.
  5. API Access for Automation

    • Fetch logs programmatically via HTTP client (e.g., cURL, Guzzle):
      $client = new Client();
      $response = $client->get('http://your-app.local/_logs/_dev');
      $logs = json_decode($response->getBody(), true);
      

Gotchas and Tips

Pitfalls

  1. Security Risks in Production

    • Never expose /_logs in production without authentication. Use middleware or firewall rules:
      # config/packages/security.yaml
      firewalls:
          main:
              context: log_viewer
              patterns:
                  ^/_logs
              form_login: ~
      
    • Add a LOG_VIEWER_ENABLED env var to disable the bundle in production:
      # .env
      LOG_VIEWER_ENABLED=false
      
  2. Log File Permissions

    • Ensure the web server user (e.g., www-data) has read access to log files:
      chmod -R 755 var/log/
      
  3. Monolog Configuration Conflicts

    • If logs don’t appear, verify Monolog’s handlers in config/packages/monolog.yaml:
      handlers:
          main:
              type: stream
              path: '%kernel.logs_dir%/%kernel.environment%.log'
              level: debug
      
  4. Routing Conflicts

    • Prefix conflicts may occur if another bundle uses /_logs. Rename the prefix:
      prefix: /debug/logs
      

Debugging Tips

  1. Check Bundle Enablement

    • Verify the bundle is loaded via:
      php bin/console debug:container Devoralive\LogViewerBundle\LogViewerBundle
      
  2. Log File Paths

    • Confirm log paths in var/log/ match the bundle’s expectations. Override if needed:
      log_viewer:
          logs_dir: '%kernel.project_dir%/custom_logs'
      
  3. JSON Parsing Issues

    • If logs return malformed JSON, validate Monolog’s formatter in config/packages/monolog.yaml:
      handlers:
          main:
              formatter: monolog.formatter.json
      
  4. Caching Headers

    • Disable caching for the log route to ensure real-time updates:
      # config/packages/framework.yaml
      http_method_override: true
      router:
          cache_warmup: false
      

Extension Points

  1. Custom Log Handlers

    • Extend the bundle to support additional log handlers (e.g., Elasticsearch, Syslog):
      // src/EventSubscriber/LogViewerSubscriber.php
      public function onKernelRequest(GetResponseEvent $event)
      {
          if ($event->isMasterRequest() && $event->getRequest()->getPathInfo() === '/_logs/_custom') {
              $logs = $this->fetchFromElasticsearch();
              $event->setResponse(new Response(json_encode($logs)));
          }
      }
      
  2. UI Customization

    • Override the Twig template (Resources/views/default/index.html.twig) to add syntax highlighting or filters:
      {% extends '@LogViewerBundle/default/index.html.twig' %}
      {% block body %}
          {{ parent() }}
          <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
          <script>Prism.highlightAll();</script>
      {% endblock %}
      
  3. Event Listeners

    • Hook into log generation to preprocess entries (e.g., redact sensitive data):
      // src/EventSubscriber/LogRedactorSubscriber.php
      public function onKernelRequest(GetResponseEvent $event)
      {
          if ($event->getRequest()->getPathInfo() === '/_logs/_dev') {
              $logs = $this->redactLogs($this->getLogs());
              $event->setResponse(new Response(json_encode($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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime