Logging

Logging and Exception Reporting

Laravel 2,157 logs through Monolog 21,402 . config/logging.php defines channels such as single, daily, stderr, syslog and slack, and stack sends each message to every channel in LOG_STACK. Log::info('Product created', ['id' => $product->id]) writes one line with its context as JSON. Context::add('customer', 42) attaches data to every entry for the rest of the request, and to any jobs the request queues. Exceptions that nothing catches are reported, which means logged, before they are rendered. You shape that in bootstrap/app.php:

bootstrap/app.php: global context and an exception that is never loggedPHP
->withExceptions(function (Exceptions $exceptions): void {
    $exceptions->context(fn () => ['release' => basename(base_path())]);
    $exceptions->dontReport(ConnectionException::class);
    // ...the skeleton's shouldRenderJsonWhen() call stays below
})

A test route threw RuntimeException('Rate service returned 503'), and its entry in storage/logs/laravel.log carried {"release":"app"}, the trace and {"customer":42}. The skeleton includes Laravel Pail 926 1.2.7 (it needs pcntl), which follows the log live and can narrow it with --filter, --level and --user:

Output of 208
$ php artisan pail
   INFO  Tailing application logs.                        Press Ctrl+C to exit
                                               Use -v|-vv to show more details
┌ 08:58:42 RuntimeException ──────────────────────────────── routes/web.php:25 ┐
│ Rate service returned 503                                                    │
└────────────────────────────────── GET: /boom • Auth ID: guest • customer: 42 ┘

Pail works with any log driver, not just files. For quick looks, dump() and dd() (var_dump and VarDumper) work everywhere, and ->dd() on a query builder prints its SQL and bindings.