Introduction
Flare can collect and display your application's log messages. This gives you insight into what your application is doing, beyond just error tracking.
Log collection requires Laravel 10 or newer.
Setting up the logging channel
To feed logs from Laravel to Flare, add the following channel to your config/logging.php file:
'channels' => [
// other channels...
'flare' => [
'driver' => 'flare',
],
],
Then add the Flare channel to the LOG_STACK variable in your .env file:
LOG_STACK=single,flare
Now any log call in your application will also be sent to Flare:
Log::info('User signed in', ['user_id' => 42]);
Log::warning('Slow query detected');
The array passed as the second argument is attached as context to that single log entry. If you want a value to be attached to every log entry (and every error report) instead, use custom context. Anything you store via Laravel's Context facade is also picked up automatically. See Laravel context for details.
Laravel Cloud
Laravel Cloud defines its own laravel-cloud-socket log channel at runtime and overrides the channel in your config. Don't add the Flare channel to it. Register the flare channel in config/logging.php as shown above, then set your log stack through environment variables:
LOG_CHANNEL=stack
LOG_STACK=laravel-cloud-socket,flare
Add these on cloud.laravel.com, under Application Settings > General, in the "Custom environment variables" section. LOG_CHANNEL also appears in the read only "Injected variables" section. Custom variables take priority over injected ones, so your own LOG_CHANNEL is the one that counts.
Keep laravel-cloud-socket in LOG_STACK, or the Laravel Cloud dashboard stops receiving log entries.
The change takes effect after a redeploy.
Laravel Vapor
When using Laravel Vapor, you should use a vapor channel that combines the Flare channel with stderr:
'channels' => [
// other channels...
'flare' => [
'driver' => 'flare',
],
'vapor' => [
'driver' => 'stack',
'channels' => ['flare', 'stderr'],
'ignore_exceptions' => false,
],
],
Then set the log channel in your .env file:
LOG_CHANNEL=vapor
Setting a minimal log level
Flare sends every log entry by default. Set the minimal_log_level key in your config/flare.php file to only send entries at or above a given severity:
// config/flare.php
return [
// other options...
'minimal_log_level' => \Monolog\Level::Warning,
];
With the level above, Flare sends Log::warning(), Log::error(), Log::critical(), Log::alert(), and Log::emergency(). It ignores Log::debug(), Log::info(), and Log::notice().
Shipping logs under high load
By default, logs are shipped over HTTP at the end of each request together with the rest of the request's telemetry. That works well for most applications, but once log volume picks up the per request HTTP round trip can start to weigh on your workers.
If you're sending a lot of logs, run the Flare daemon alongside your application. The daemon takes the upstream delivery off the request path entirely so log volume doesn't slow your application down. See the Flare daemon page for setup details.
Manually recording logs
If you're writing log messages outside of Laravel's logging system, you can record them manually. The PHP documentation provides a full overview of all available recorder methods. When using these methods in Laravel, use the Flare facade instead of $flare:
use Spatie\LaravelFlare\Facades\Flare;
use Monolog\Level;
Flare::log()->record(
message: 'This is a log message',
level: Level::Info,
context: ['team_id' => 1],
);
Disabling log collection
To disable log collection, set FLARE_LOG=false in your .env file, or set the log key in your config/flare.php file to false.