eurekos / symfony-monolog-viewer
A simple Symfony bundle to view Monolog log files in the browser.
Package info
github.com/eurekos/symfony-monolog-viewer
Type:symfony-bundle
pkg:composer/eurekos/symfony-monolog-viewer
Requires
- php: >=8.1
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/routing: ^6.4 || ^7.0 || ^8.0
- symfony/twig-bundle: ^6.4 || ^7.0 || ^8.0
- twig/twig: ^3.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-11-07 12:37:06 UTC
README
A Symfony bundle to view Monolog log files in the browser.
What it does:
- Lists the
.logfiles in your log directory (by defaultvar/log). - Shows the last lines of a file, parsed into entries (time, level, channel, message), newest first. Multi-line entries such as stack traces stay grouped.
It reads log files from a directory. That covers Monolog's common
file-based handlers (StreamHandler, RotatingFileHandler). Logs sent only to
other destinations (syslog, a database, a remote service, etc.) are not shown,
because there is no file to read.
Requirements
- PHP 8.1+
- Symfony 6.4, 7.x or 8.x (
symfony/twig-bundle)
Installation
composer require eurekos/symfony-monolog-viewer
If you don't use Symfony Flex, register the bundle manually in
config/bundles.php:
return [ // ... Eurekos\SymfonyMonologViewer\EurekosSymfonyMonologViewerBundle::class => ['all' => true], ];
Configuration (optional)
Defaults are usually fine. To override the directory or how many lines are
tailed, create config/packages/eurekos_symfony_monolog_viewer.yaml:
eurekos_symfony_monolog_viewer: dir: '%kernel.logs_dir%' # default: your var/log max_lines: 200 # default: 200
Setup
This bundle ships an abstract controller. You enable the viewer by extending it in your own application: you choose the path prefix and the access control, and the routes are inherited from the base controller.
Create src/Controller/MonologViewerController.php:
namespace App\Controller; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; use Eurekos\SymfonyMonologViewer\Controller\MonologViewerController as BaseMonologViewerController; #[Route('/admin/logs')] // path prefix for the controllers #[IsGranted('ROLE_ADMIN')] // alternatively, protect it with a firewall final class MonologViewerController extends BaseMonologViewerController { }
With the default Symfony route configuration (which loads attribute routes from
src/Controller/), this registers:
| Route name | Path |
|---|---|
eurekos_monolog_viewer_index |
/admin/logs |
eurekos_monolog_viewer_file |
/admin/logs/{name} |
The viewer is then available at /admin/logs.
Notes
-
The base controller is autowired into your subclass automatically (it needs Twig and an internal log-reading service). You don't declare a constructor unless you want to.
-
Create exactly one subclass. The route names are defined on the base controller's actions, so several subclasses would clash.
-
Don't set a
name:prefix on the class-level#[Route], otherwise the internal template links (which use the route names above) won't resolve. -
If you prefer a firewall to
#[IsGranted], guard the prefix instead:# config/packages/security.yaml access_control: - { path: ^/admin/logs, roles: ROLE_ADMIN }
Log files can contain sensitive data, so always protect your route. (Output is HTML-escaped by Twig, so log content can't inject markup into the page.)
How it works
LogManager lists *.log files in the configured directory and, for a chosen
file, reads the last max_lines lines by scanning backwards from the end of the
file (so large files aren't loaded into memory). Lines matching Monolog's
default format are parsed; lines that don't match are treated as continuations
of the previous entry.
License
MIT. See LICENSE.