cyve/logviewer-bundle
Symfony bundle that adds a lightweight log viewer to your app. Install via Composer, enable the bundle, and import its routes. Super admins (ROLE_SUPER_ADMIN) can browse application logs at /logs to quickly inspect recent entries and errors.
Installation Run:
composer require cyve/logviewer-bundle
Ensure the bundle is enabled in config/bundles.php:
Cyve\LogViewerBundle\CyveLogViewerBundle::class => ['all' => true],
Routing
Import the routes in config/routes/cyve_log_viewer.yaml:
cyve_log_viewer:
resource: "@CyveLogViewerBundle/Resources/config/routing.yaml"
First Access
/logs in your browser.ROLE_SUPER_ADMIN role (default requirement)./logs endpoint.ERROR, INFO) or keyword.Development Debugging
POST /api/endpoint.Production Monitoring (Caution)
Custom Log Levels
LogViewerController and modifying the getLevels() method.Log File Paths
log_paths parameter in config/packages/cyve_log_viewer.yaml:
cyve_log_viewer:
log_paths: ['%kernel.logs_dir%/app.log', '%kernel.logs_dir%/debug.log']
Symfony Event Listeners
Integrate with Symfony’s kernel.log event to dynamically inject metadata into logs (e.g., user IDs, request IDs) for easier filtering:
// src/EventListener/LogListener.php
public function onKernelLog(GetResponseForExceptionEvent $event) {
$logEntry = $event->getLogEntry();
$logEntry->setExtra(['user_id' => $this->getCurrentUserId()]);
}
Security Integration
Replace the default ROLE_SUPER_ADMIN check with a custom voter or access control list (ACL) for granular permissions:
# config/packages/security.yaml
access_control:
- { path: ^/logs, roles: ROLE_LOG_VIEWER }
Performance Overhead
cyve_log_viewer.cache_enabled: true).Log Rotation
monolog rotating logs). Old logs might appear broken or incomplete.monolog is configured to retain logs in a readable format during rotation:
monolog:
handlers:
main:
type: rotating_file
max_files: 30
filename: "%kernel.logs_dir%/%kernel.environment%.log"
Missing Logs
file_put_contents) won’t appear in the viewer.LoggerInterface or Monolog for consistency.CSRF Protection
/logs endpoint may lack CSRF protection by default.@Security annotations or configure Symfony’s csrf_token middleware to exclude it if safe:
# config/packages/framework.yaml
framework:
csrf_protection:
enabled: true
ignore_routes:
- cyve_log_viewer_logs
Log Viewer Not Showing Logs
log_paths configuration matches your actual log file locations.chmod -R 755 var/logs).Blank Page or 404
bundles.php.php bin/console cache:clear
Custom Log Formatting
templates/logs/index.html.twig) to customize the log display (e.g., add collapsible sections).Custom Log Filters
Extend the LogFilter service to add dynamic filters (e.g., by request ID):
// src/Service/CustomLogFilter.php
public function filter(array $logs, string $query) {
return array_filter($logs, function ($log) use ($query) {
return strpos($log['message'], $query) !== false ||
isset($log['extra']['request_id']) && strpos($log['extra']['request_id'], $query) !== false;
});
}
Log Export Add a route to export logs as JSON or CSV by extending the controller:
// src/Controller/LogExportController.php
public function export(Request $request) {
$logs = $this->logViewer->getLogs();
return new JsonResponse($logs);
}
Real-Time Updates Use Symfony UX Turbo or Mercure to push log updates to the client without polling:
# config/packages/messenger.yaml
framework:
messenger:
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
Environment-Specific Logs
The bundle defaults to showing logs for the current environment. Override in config/packages/cyve_log_viewer.yaml:
cyve_log_viewer:
environments: [dev, staging] # Show logs only for these environments
Log Level Whitelisting
Restrict visible log levels to ERROR and CRITICAL in production:
cyve_log_viewer:
levels: [ERROR, CRITICAL]
How can I help you explore Laravel packages today?