Laravel logs from web, queue and cron in one live view
Make socket your Laravel log channel: add it to config/logging.php with Monolog's SocketHandler and the JsonFormatter, then set LOG_CHANNEL=socket. Your logs appear live in Buggregator, with the context as formatted JSON, instead of in a file you tail -f.
Steps
1. Add the socket channel
Add the channel to config/logging.php. The JSON formatter is required.
// config/logging.php
return [
// ...
'channels' => [
// ...
'socket' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => \Monolog\Handler\SocketHandler::class,
'formatter' => \Monolog\Formatter\JsonFormatter::class,
'handler_with' => [
'connectionString' => env('LOG_SOCKET_URL', '127.0.0.1:9913'),
],
],
],
];2. Switch your app to it
Set two lines in .env. This sends logs to Buggregator instead of your current channel, for example stack and its files. In Docker Compose, replace 127.0.0.1 with the Buggregator service name, for example buggregator:9913.
LOG_CHANNEL=socket
LOG_SOCKET_URL=127.0.0.1:99133. Open the UI
Open http://127.0.0.1:8000. New records appear as they are written, each with its channel, level, message and context. Search finds records by message, channel or level.
4. Run your workers as usual
Queue consumers, cron jobs and daemons write logs that are easy to miss in stdout. With the same .env, they log to the same view as your web requests.
Why it works
Monolog's SocketHandler writes each record to a TCP address instead of a file. Buggregator listens on port 9913 and reads the JSON records. Every process that uses the socket channel sends to the same place, so you read them side by side, next to your exceptions and dumps.
Related tips
- Logs
Symfony logs in a live view, context as JSON
Add one Monolog socket handler with the JSON formatter, and your Symfony logs appear live in Buggregator with channel, level and context.
- Dumps
dump() without breaking your page or JSON response
Send Symfony VarDumper output to Buggregator with two env vars. dump() stops landing in your HTML or JSON and shows the file and line it came from.
- Dumps
Send ray() calls to a free local viewer
Set RAY_HOST and RAY_PORT in your Laravel .env. Your ray() calls, queries, jobs and mails show up in Buggregator, free and MIT licensed.
Checked on with Buggregator v2.8.0