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:
$config->log(true);
You can also set a minimal log level so that only logs at or above that severity are sent:
use Monolog\Level;
$config->log(true, minimalLevel: Level::Warning);
Recording logs
We cannot automatically collect logs in the framework-agnostic version of the package. You can manually record logs using the Logger:
use Monolog\Level;
$flare->log()->record('Something happened', Level::Info);
You can also pass additional context:
$flare->log()->record(
message: 'User signed in',
level: Level::Info,
context: ['user_id' => 42],
);
You can read more about the available log levels and how they interact in the levels documentation.
Using the Monolog handler
Flare ships with a Monolog handler that you can add to any Monolog logger instance:
use Monolog\Logger;
use Monolog\Level;
use Spatie\FlareClient\Support\FlareLogHandler;
$monolog = new Logger('app');
$monolog->pushHandler(new FlareLogHandler($flare->logger, Level::Debug));
$monolog->info('This will be sent to Flare');
This is especially useful if your application already uses Monolog for logging.
Shipping logs under high load
By default, logs are shipped over HTTP when the application lifecycle flushes (typically at the end of a request, job, or command). 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 your application's hot path entirely so log volume doesn't slow your application down. See the Flare daemon page for setup details.
Disabling log collection
To disable log collection:
$config->log(false);