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

Easyadmin Log Viewer Bundle Laravel Package

codebuds/easyadmin-log-viewer-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require codebuds/easyadmin-log-viewer-bundle
    

    Ensure config/bundles.php includes the bundle if not using Symfony Flex.

  2. First Use Case: Access the log viewer via the admin route (default: /admin/log-viewer). No additional configuration is required for basic functionality.

  3. Key Actions:

    • Browse log files (e.g., app.log, prod.log) from the EasyAdmin dashboard.
    • Filter logs by channel (e.g., doctrine, monolog) and level (e.g., ERROR, DEBUG).
    • Click a log entry to expand stack traces and multiline messages.

Implementation Patterns

Workflows

  1. Integrating with Existing Admin:

    • The bundle auto-registers a menu item in EasyAdmin’s sidebar under Log Viewer.
    • Customize the menu position by overriding the easy_admin configuration:
      easy_admin:
          menu:
              - { label: 'Logs', route: 'easy_admin_log_viewer.index', icon: 'fas fa-file-alt' }
      
  2. Log Filtering:

    • Use the dropdowns in the UI to filter logs dynamically (e.g., show only ERROR logs from the doctrine channel).
    • For programmatic filtering, extend the bundle’s LogEntry entity (see Extension Points).
  3. Log Actions:

    • Download: Click the download button to fetch raw log files.
    • Delete: Use the trash icon to remove log files (requires GUF permissions; see Gotchas).
  4. Customizing Log Display:

    • Override the Twig templates (templates/easy_admin_log_viewer/) to modify how logs are rendered.
    • Example: Add a custom column for timestamps:
      {# templates/easy_admin_log_viewer/index.html.twig #}
      <th>{{ 'Timestamp'|trans }}</th>
      {% for entry in entries %}
          <td>{{ entry.timestamp|date('Y-m-d H:i:s') }}</td>
      {% endfor %}
      
  5. Programmatic Access:

    • Inject the LogViewerService to fetch logs programmatically:
      use CodeBuds\EasyAdminLogViewerBundle\Service\LogViewerService;
      
      public function __construct(private LogViewerService $logViewer) {}
      
      $logs = $this->logViewer->getLogs(['channel' => 'doctrine', 'level' => 'ERROR']);
      

Gotchas and Tips

Pitfalls

  1. Permissions:

    • Log deletion requires ROLE_ADMIN or custom permissions. Override the voter:
      // src/Security/Voter/LogViewerVoter.php
      public function supports(string $attribute, $subject): bool
      {
          return $attribute === 'DELETE' && $subject instanceof LogFile;
      }
      
  2. Log File Paths:

    • The bundle defaults to Symfony’s log/ directory. To customize paths, override the log_paths config:
      easy_admin_log_viewer:
          log_paths:
              - '%kernel.logs_dir%/custom_logs'
              - '/var/custom/logs'
      
  3. Performance:

    • Large log files (>10MB) may cause UI lag. Use the max_log_size config to limit displayed entries:
      easy_admin_log_viewer:
          max_log_size: 5000  # Max 5,000 lines
      
  4. Monolog Integration:

    • Ensure your monolog.yaml includes handlers for the channels you want to filter:
      handlers:
          main:
              type: stream
              path: '%kernel.logs_dir%/%kernel.environment%.log'
              channels: ['!event']
      

Debugging

  1. Log Parsing Errors:

    • If stack traces appear broken, verify your log format matches Monolog’s default:
      monolog:
          handlers:
              main:
                  formatter: monolog.formatter.line
      
    • For custom formats, extend the LogParser service:
      // src/Service/CustomLogParser.php
      class CustomLogParser extends AbstractLogParser
      {
          public function parseLine(string $line): LogEntry
          {
              // Custom parsing logic
          }
      }
      
      Register it in services.yaml:
      services:
          CodeBuds\EasyAdminLogViewerBundle\Service\LogParser:
              alias: App\Service\CustomLogParser
      
  2. Missing Log Files:

    • Check log_paths in config and ensure files are writable:
      chmod -R 775 %kernel.logs_dir%
      

Extension Points

  1. Custom Log Sources:

    • Add support for non-Monolog logs (e.g., database logs) by implementing LogSourceInterface:
      class DatabaseLogSource implements LogSourceInterface
      {
          public function getLogs(array $filters): array
          {
              // Query DB and return LogEntry objects
          }
      }
      
      Register it in services.yaml:
      services:
          App\Service\DatabaseLogSource:
              tags: ['easy_admin_log_viewer.log_source']
      
  2. Custom Actions:

    • Add buttons (e.g., "Clear Log") by extending the LogEntry Twig template:
      <td>
          <button onclick="clearLog('{{ entry.file }}')">Clear</button>
      </td>
      
      Add JavaScript to handle the action:
      function clearLog(file) {
          fetch(`/admin/log-viewer/clear?file=${file}`, { method: 'POST' });
      }
      
  3. Styling:

    • Override Bootstrap classes in the config to match your theme:
      easy_admin_log_viewer:
          levels:
              - { level: 'ERROR', class: 'text-red-600 bg-red-50' }  # Tailwind example
      
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