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

Oro Log Viewer Laravel Package

allies/oro-log-viewer

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require allies/oro-log-viewer
    

    Ensure your project uses OroCRM 2.x (as per composer.json constraints).

  2. Enable the Bundle: Add to config/bundles.php:

    Allies\LogViewerBundle\AlliesLogViewerBundle::class => ['all' => true],
    
  3. First Use Case: Access logs via the admin UI at /allies/logviewer. The bundle provides a file browser for /var/log/ (default) and supports:

    • Viewing raw log files (.log, .txt).
    • Searching log content via grep-like syntax (added in v1.1.0).

Implementation Patterns

Core Workflows

  1. Log Browsing:

    • Navigate to /allies/logviewer to list log files in the configured directory (default: /var/log/).
    • Click a file to view its contents in a paginated UI (20 lines/page by default).
  2. Searching Logs:

    • Use the grep endpoint for programmatic searches:
      /allies/logviewer/file/grep/{file}/{pattern}/{start}?/{limit}?/{caseSensitive}?
      
      • Example: Search for ERROR in app.log (case-insensitive, first 50 results):
        /allies/logviewer/file/grep/app.log/ERROR/0/50/false
        
    • Frontend Integration: Extend the UI by adding a search form to submit grep queries via AJAX.
  3. CSV Support (v1.2.0+):

    • Automatically detects and renders .csv files in the logs directory as tables.
  4. Custom Log Directories:

    • Override the default log path via config:
      # config/packages/allies_log_viewer.yaml
      allies_log_viewer:
          log_directory: '%kernel.logs_dir%/custom'  # e.g., /var/log/myapp/custom
      

Integration Tips

  • OroCRM-Specific: Leverage Oro’s entity-aware routing to restrict log access by user roles (e.g., ROLE_ADMIN). Example in security.yaml:

    access_control:
        - { path: ^/allies/logviewer, roles: ROLE_ADMIN }
    
  • Event Listeners: Hook into Oro’s oro_integration events to log custom data, then view it via this bundle.

  • API Wrappers: For headless use, wrap the grep endpoint in a service:

    use Allies\LogViewerBundle\Service\LogViewerService;
    
    $service = $this->container->get(LogViewerService::class);
    $results = $service->grep('app.log', 'ERROR', 0, 50, false);
    

Gotchas and Tips

Pitfalls

  1. Filename Parsing Issues:

    • Files with periods in names (e.g., backup.2023.log) may fail to render in older versions (<1.2.0). Upgrade or manually whitelist directories.
  2. Permission Errors:

    • The bundle reads logs as the web server user (e.g., www-data). Ensure:
      chmod -R 755 /var/log/  # Adjust permissions if logs are inaccessible.
      
  3. OroCRM Version Lock:

    • Hard dependency on OroCRM 2.x. Attempting to use with Oro 3.x+ will break routing/dependency injection.
  4. Grep Limitations:

    • The grep endpoint is not regex-aware—use literal strings only.
    • Case sensitivity is strict unless explicitly disabled (caseSensitive=false).
  5. Memory Leaks:

    • Large log files (>10MB) may cause timeouts. Use limit to paginate results:
      /allies/logviewer/file/grep/app.log/ERROR/0/100
      

Debugging

  • Check Routes: Dump routes to verify the bundle is registered:

    php bin/console debug:router | grep allies/logviewer
    

    Expected output:

    allies_logviewer_file_index    GET        ANY      ANY    /allies/logviewer/file/{file}
    allies_logviewer_file_grep     GET        ANY      ANY    /allies/logviewer/file/grep/{file}/{pattern}/{start}/{limit}/{caseSensitive}
    
  • Log Directory Validation: Add a custom command to verify log paths:

    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class CheckLogViewer extends Command {
        protected function execute(InputInterface $input, OutputInterface $output) {
            $directory = $this->container->getParameter('allies_log_viewer.log_directory');
            if (!is_dir($directory)) {
                throw new \RuntimeException("Log directory {$directory} does not exist.");
            }
            $output->writeln("✅ Log directory validated: {$directory}");
        }
    }
    

Extension Points

  1. Custom File Types: Override the file renderer by extending the Allies\LogViewerBundle\Twig\LogExtension class and binding it in services.yaml:

    allies_log_viewer.twig.log_extension:
        class: App\Twig\CustomLogExtension
        tags: ['twig.extension']
    
  2. Pre-Process Logs: Add a filter pipeline before rendering. Example: Redact sensitive data:

    // src/EventListener/LogViewerFilterListener.php
    use Allies\LogViewerBundle\Event\LogFileEvent;
    
    class LogViewerFilterListener {
        public function onPreRender(LogFileEvent $event) {
            $content = $event->getContent();
            $content = preg_replace('/password=[^&]+/', 'password=[REDACTED]', $content);
            $event->setContent($content);
        }
    }
    

    Register the listener in services.yaml:

    Allies\LogViewerBundle\EventListener\LogViewerFilterListener:
        tags:
            - { name: kernel.event_listener, event: allies.logviewer.pre_render, method: onPreRender }
    
  3. Add Log Sources: Extend the file provider to include non-standard paths (e.g., S3 logs):

    // src/Service/CustomLogProvider.php
    use Allies\LogViewerBundle\Service\LogProviderInterface;
    
    class CustomLogProvider implements LogProviderInterface {
        public function getFiles(string $directory): array {
            // Fetch logs from S3, etc.
            return ['s3://logs/app.log' => 'App Logs'];
        }
    }
    

    Override the service in services.yaml:

    Allies\LogViewerBundle\Service\LogProvider:
        class: App\Service\CustomLogProvider
    
  4. UI Customization: Override the Twig templates in templates/bundles/AlliesLogViewer/ to modify the UI (e.g., add syntax highlighting for code blocks).

Performance Tips

  • Cache Grep Results: For frequently searched patterns, cache results in Redis:

    $cacheKey = "log_grep_{$file}_{$pattern}_{$start}_{$limit}";
    $results = $cache->get($cacheKey) ?: $service->grep($file, $pattern, $start, $limit);
    $cache->set($cacheKey, $results, 3600); // Cache for 1 hour
    
  • Compress Large Logs: Use gzip for log rotation to reduce I/O:

    logrotate -z /etc/logrotate.conf
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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