Installation:
composer require allies/oro-log-viewer
Ensure your project uses OroCRM 2.x (as per composer.json constraints).
Enable the Bundle:
Add to config/bundles.php:
Allies\LogViewerBundle\AlliesLogViewerBundle::class => ['all' => true],
First Use Case:
Access logs via the admin UI at /allies/logviewer. The bundle provides a file browser for /var/log/ (default) and supports:
.log, .txt).Log Browsing:
/allies/logviewer to list log files in the configured directory (default: /var/log/).Searching Logs:
/allies/logviewer/file/grep/{file}/{pattern}/{start}?/{limit}?/{caseSensitive}?
ERROR in app.log (case-insensitive, first 50 results):
/allies/logviewer/file/grep/app.log/ERROR/0/50/false
CSV Support (v1.2.0+):
.csv files in the logs directory as tables.Custom Log Directories:
# config/packages/allies_log_viewer.yaml
allies_log_viewer:
log_directory: '%kernel.logs_dir%/custom' # e.g., /var/log/myapp/custom
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);
Filename Parsing Issues:
backup.2023.log) may fail to render in older versions (<1.2.0). Upgrade or manually whitelist directories.Permission Errors:
www-data). Ensure:
chmod -R 755 /var/log/ # Adjust permissions if logs are inaccessible.
OroCRM Version Lock:
Grep Limitations:
caseSensitive=false).Memory Leaks:
limit to paginate results:
/allies/logviewer/file/grep/app.log/ERROR/0/100
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}");
}
}
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']
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 }
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
UI Customization:
Override the Twig templates in templates/bundles/AlliesLogViewer/ to modify the UI (e.g., add syntax highlighting for code blocks).
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
How can I help you explore Laravel packages today?