# 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 PHP 8.1 or newer.

## Enabling log collection

Log collection is disabled by default. To enable it:

```php
$config->log(true);
```

You can also set a minimal log level so that only logs at or above that severity are sent:

```php
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`:

```php
use Monolog\Level;

$flare->log()->record('Something happened', Level::Info);
```

You can also pass additional context for a single log entry:

```php
$flare->log()->record(
    message: 'User signed in',
    level: Level::Info,
    context: ['user_id' => 42],
);
```

If you want a value to be attached to every log entry (and every error report) instead of a single one, use [custom context](/docs/php/data-collection/custom-context).

You can read more about the available log levels and how they interact in the [levels](/docs/php/logs/levels) documentation.

## Using the Monolog handler

Flare ships with a Monolog handler that you can add to any Monolog logger instance:

```php
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.

The array you pass as the second argument to Monolog's log methods is forwarded as context for that single log entry:

```php
$monolog->info('User signed in', ['user_id' => 42]);
```

For values that should be attached to every log entry (and every error report and trace), use [custom context](/docs/php/data-collection/custom-context) instead.

## 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](/docs/php/general/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](/docs/php/general/flare-daemon) page for setup details.

## Disabling log collection

To disable log collection:

```php
$config->log(false);
```
