Installation
composer require devoralive/log-viewer-bundle
Ensure your composer.json includes the package under require.
Enable the Bundle
Add to config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):
Devoralive\LogViewerBundle\LogViewerBundle::class => ['all' => true],
Route Configuration
Add to config/routes.yaml (Symfony 4+) or app/config/routing.yml (Symfony 3):
log_viewer:
resource: "@LogViewerBundle/Resources/config/routing.yml"
prefix: /_logs
First Use Case Access logs via browser:
http://your-app.local/_logs/_devhttp://your-app.local/_logs/_prodLog Inspection in Development
/_logs/_dev endpoint to debug issues by inspecting raw Monolog JSON output.ERROR, DEBUG), or channel (e.g., doctrine, security).Integration with Debug Toolbar
/_logs/_dev for quick access during development:
// src/Kernel.php (Symfony 4+)
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('log_viewer', [
'toolbar' => true,
]);
});
}
Conditional Log Exposure
# config/packages/log_viewer.yaml
log_viewer:
enabled: '%kernel.environment% != "prod"'
Custom Log Channels
config/packages/log_viewer.yaml:
log_viewer:
logs:
custom_channel: '%kernel.logs_dir%/custom.log'
/_logs/_custom_channel.API Access for Automation
$client = new Client();
$response = $client->get('http://your-app.local/_logs/_dev');
$logs = json_decode($response->getBody(), true);
Security Risks in Production
/_logs in production without authentication. Use middleware or firewall rules:
# config/packages/security.yaml
firewalls:
main:
context: log_viewer
patterns:
^/_logs
form_login: ~
LOG_VIEWER_ENABLED env var to disable the bundle in production:
# .env
LOG_VIEWER_ENABLED=false
Log File Permissions
www-data) has read access to log files:
chmod -R 755 var/log/
Monolog Configuration Conflicts
handlers in config/packages/monolog.yaml:
handlers:
main:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
level: debug
Routing Conflicts
/_logs. Rename the prefix:
prefix: /debug/logs
Check Bundle Enablement
php bin/console debug:container Devoralive\LogViewerBundle\LogViewerBundle
Log File Paths
var/log/ match the bundle’s expectations. Override if needed:
log_viewer:
logs_dir: '%kernel.project_dir%/custom_logs'
JSON Parsing Issues
formatter in config/packages/monolog.yaml:
handlers:
main:
formatter: monolog.formatter.json
Caching Headers
# config/packages/framework.yaml
http_method_override: true
router:
cache_warmup: false
Custom Log Handlers
// src/EventSubscriber/LogViewerSubscriber.php
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->isMasterRequest() && $event->getRequest()->getPathInfo() === '/_logs/_custom') {
$logs = $this->fetchFromElasticsearch();
$event->setResponse(new Response(json_encode($logs)));
}
}
UI Customization
Resources/views/default/index.html.twig) to add syntax highlighting or filters:
{% extends '@LogViewerBundle/default/index.html.twig' %}
{% block body %}
{{ parent() }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script>Prism.highlightAll();</script>
{% endblock %}
Event Listeners
// src/EventSubscriber/LogRedactorSubscriber.php
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequest()->getPathInfo() === '/_logs/_dev') {
$logs = $this->redactLogs($this->getLogs());
$event->setResponse(new Response(json_encode($logs)));
}
}
How can I help you explore Laravel packages today?