codebuds/easyadmin-log-viewer-bundle
Installation:
composer require codebuds/easyadmin-log-viewer-bundle
Ensure config/bundles.php includes the bundle if not using Symfony Flex.
First Use Case:
Access the log viewer via the admin route (default: /admin/log-viewer). No additional configuration is required for basic functionality.
Key Actions:
app.log, prod.log) from the EasyAdmin dashboard.doctrine, monolog) and level (e.g., ERROR, DEBUG).Integrating with Existing Admin:
Log Viewer.easy_admin configuration:
easy_admin:
menu:
- { label: 'Logs', route: 'easy_admin_log_viewer.index', icon: 'fas fa-file-alt' }
Log Filtering:
ERROR logs from the doctrine channel).LogEntry entity (see Extension Points).Log Actions:
GUF permissions; see Gotchas).Customizing Log Display:
templates/easy_admin_log_viewer/) to modify how logs are rendered.{# 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 %}
Programmatic Access:
LogViewerService to fetch logs programmatically:
use CodeBuds\EasyAdminLogViewerBundle\Service\LogViewerService;
public function __construct(private LogViewerService $logViewer) {}
$logs = $this->logViewer->getLogs(['channel' => 'doctrine', 'level' => 'ERROR']);
Permissions:
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;
}
Log File Paths:
log/ directory. To customize paths, override the log_paths config:
easy_admin_log_viewer:
log_paths:
- '%kernel.logs_dir%/custom_logs'
- '/var/custom/logs'
Performance:
max_log_size config to limit displayed entries:
easy_admin_log_viewer:
max_log_size: 5000 # Max 5,000 lines
Monolog Integration:
monolog.yaml includes handlers for the channels you want to filter:
handlers:
main:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
channels: ['!event']
Log Parsing Errors:
monolog:
handlers:
main:
formatter: monolog.formatter.line
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
Missing Log Files:
log_paths in config and ensure files are writable:
chmod -R 775 %kernel.logs_dir%
Custom Log Sources:
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']
Custom Actions:
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' });
}
Styling:
easy_admin_log_viewer:
levels:
- { level: 'ERROR', class: 'text-red-600 bg-red-50' } # Tailwind example
How can I help you explore Laravel packages today?