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.
Enabling log collection
Log collection is disabled by default. To enable it, set the log key to true in your config/flare.php file:
'log' => true,
You can also set a minimal log level so that only logs at or above that severity are sent:
'minimal_log_level' => \Monolog\Level::Warning,
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.
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');
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
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 the log key to false in your config/flare.php file:
// config/flare.php
'log' => false,