Skip to main content

Symfony logs in a live view, context as JSON

To stop tailing var/log/dev.log, add one socket handler to your Symfony Monolog config with the monolog.formatter.json formatter and point it at 127.0.0.1:9913. Every log record then appears live in Buggregator, with its channel, level, message and context as formatted JSON.

Steps

1. Add a socket handler for dev

Put the handler in config/packages/dev/monolog.php. If that file already configures handlers, add the socket handler to the existing chain instead of replacing it. The monolog.formatter.json formatter is required: without it, Buggregator cannot parse the log records.

php
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Config\MonologConfig;

return static function (MonologConfig $monologConfig): void {
    $monologConfig
        ->handler('socket')
            ->level('debug')
            ->formatter('monolog.formatter.json')
            ->type('socket')
            ->connectionString(env('MONOLOG_SOCKET_HOST'));
};

2. Set the address

Add the Buggregator address to your .env. In Docker Compose, replace 127.0.0.1 with the Buggregator service name, for example buggregator:9913.

dotenv
MONOLOG_SOCKET_HOST=127.0.0.1:9913

3. Open the UI

Open http://127.0.0.1:8000 and use your app. New records appear as they are written. Each one shows the channel (app, security, database and so on), one of the 8 PSR-3 levels, the message, the context and extra fields as JSON. Search finds records by message, channel or level.

4. See where a record came from

When a record has a source key in its context, Buggregator shows the file, line and function that wrote it.

Why it works

Monolog's socket handler writes each record to a TCP address instead of a file. Buggregator listens on port 9913 and reads records in Monolog's JSON format. Logs from workers and other containers can go to the same address, so you see them next to your exceptions and dumps.

Checked on with Buggregator v2.8.0

Setup in 60 seconds

No registration. No account. Start it and point your app at it.

1

Start Buggregator

One file, installed with one command. The web UI opens on port 8000. Prefer containers? Use the Docker tab.

$ curl -fsSL https://raw.githubusercontent.com/buggregator/server/master/scripts/install.sh | sh
$ HTTP_ADDR=127.0.0.1:8000 \
  SMTP_ADDR=127.0.0.1:1025 \
  VAR_DUMPER_ADDR=127.0.0.1:9912 \
  MONOLOG_ADDR=127.0.0.1:9913 \
  PROXY_ADDR=127.0.0.1:8080 \
  ~/.local/bin/buggregator

The script picks the file for your CPU: Intel/AMD or ARM.

One file for Linux, macOS and Windows, about 40 MB. Nothing else to install.

This run line keeps it on this computer. Without the *_ADDR settings it listens on all network interfaces →

Rather not run a script? Download the file yourself →

Runs on Windows, macOS and Linux, on Intel/AMD and ARM.

Prefer not to do it yourself? Your AI agent can set Buggregator up for you →