---
title: "Logs"
description: "Structured logs allow you to send, view and query logs sent from your Laravel applications within Sentry."
url: https://docs.sentry.io/platforms/php/guides/laravel/logs/
---

# Set Up Logs | Sentry for Laravel

With Sentry Structured Logs, you can send text-based log information from your Laravel applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

## [Requirements](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#requirements)

Logs for Laravel are supported in Sentry Laravel SDK version `4.15.0` and above.

## [Setup](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#setup)

To configure Sentry logs, you need to set the following variables in your `.env` file:

`.env`

```bash
# ...
LOG_CHANNEL=stack
LOG_STACK=single,sentry_logs
# ...
```

You will also need to configure the Sentry Laravel SDK to enable the logging integration. You can do this by updating your `.env` file to include the following:

`.env`

```bash
# ...
SENTRY_ENABLE_LOGS=true
# ...
```

You can configure your log level by setting `LOG_LEVEL` or if you want a log level just for Sentry, you can use `SENTRY_LOG_LEVEL`:

`.env`

```bash
# ...
LOG_LEVEL=info # defaults to debug
SENTRY_LOG_LEVEL=warning # defaults to LOG_LEVEL
# ...
```

Also make sure your `config/sentry.php` file is up to date. You can find the latest version on [GitHub](https://github.com/getsentry/sentry-laravel/blob/master/config/sentry.php).

##### Note

If you’re using the Sentry Laravel SDK version `4.16.0` and below, or if you want to define the channel yourself to pass additional options, configure the log channel manually as described below.

To configure Sentry as a log channel, add the following config to the `channels` section in `config/logging.php`. If this file does not exist, run `php artisan config:publish logging` to publish it.

`config/logging.php`

```php
'channels' => [
    // ...
    'sentry_logs' => [
        'driver' => 'sentry_logs',
        // The minimum logging level at which this handler will be triggered
        // Available levels: debug, info, notice, warning, error, critical, alert, emergency
        'level' => env('LOG_LEVEL', 'info'), // defaults to `debug` if not set
    ],
],
```

## [Usage](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#usage)

Once you have configured Sentry as a log channel, you can use Laravel's built-in logging functionality to send logs to Sentry:

```php
use Illuminate\Support\Facades\Log;

// Log to all channels in the stack (including Sentry)
Log::info('This is an info message');
Log::warning('User {id} failed to login.', ['id' => $user->id]);
Log::error('This is an error message');

// Log directly to the Sentry channel
Log::channel('sentry_logs')->error('This will only go to Sentry');
```

You can pass additional attributes directly to the logging functions. These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.

```php
use Illuminate\Support\Facades\Log;

Log::error('Something went wrong', [
    'user_id' => auth()->id(),
    'action' => 'update_profile',
    'additional_data' => $data,
]);
```

## [Automatic Log Flushing](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#automatic-log-flushing)

Laravel already flushes the Sentry log handler when a request, command, or job finishes. If a single request, command, or job can produce a high volume of logs, set `SENTRY_LOG_FLUSH_THRESHOLD` to send partial log batches before it completes.

`.env`

```bash
SENTRY_ENABLE_LOGS=true
SENTRY_LOG_FLUSH_THRESHOLD=5
```

We don't recommend flushing too often, because each flush sends a network request and can add latency. If you expect frequent flushes for a request, command, or job, a local [Relay](https://docs.sentry.io/product/relay/getting-started.md) can help reduce that added latency.

## [Options](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#options)

#### [before\_send\_log](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#before_send_log)

To filter logs, or update them before they are sent to Sentry, you can use the `before_send_log` option.

`config/sentry.php`

```php
'before_send_log' => [App\Exceptions\Sentry::class, 'beforeSendLog'],
```

Then implement the callback:

`app/Exceptions/Sentry.php`

```php
class Sentry
{
    public static function beforeSendLog(\Sentry\Logs\Log $log): ?\Sentry\Logs\Log
    {
        if ($log->getLevel() === \Sentry\Logs\LogLevel::info()) {
            // Filter out all info logs.
            return null;
        }

        return $log;
    }
}
```

The `before_send_log` function receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it.

## [Best Practices](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#best-practices)

### [Wide Events Over Scattered Logs](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#wide-events-over-scattered-logs)

Instead of many thin logs that are hard to correlate, emit one comprehensive log per operation with all relevant context.

This makes debugging dramatically faster — one query returns everything about a specific order, user, or request.

```php
// ❌ Scattered thin logs
\Sentry\logger()->info('Starting checkout');
\Sentry\logger()->info('Validating cart');
\Sentry\logger()->info('Processing payment');
\Sentry\logger()->info('Checkout complete');

// ✅ One wide event with full context
\Sentry\logger()->info('Checkout completed', attributes: [
    'order_id' => $order->id,
    'user_id' => $user->id,
    'user_tier' => $user->subscription,
    'cart_value' => $cart->total,
    'item_count' => count($cart->items),
    'payment_method' => 'stripe',
    'duration_ms' => (microtime(true) - $startTime) * 1000,
]);
```

### [Include Business Context](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#include-business-context)

Add attributes that help you prioritize and debug:

* **User context** — tier, account age, lifetime value
* **Transaction data** — order value, item count
* **Feature state** — active feature flags
* **Request metadata** — endpoint, method, duration

This lets you filter logs by high-value customers or specific features.

```php
\Sentry\logger()->info('API request completed', attributes: [
    // User context
    'user_id' => $user->id,
    'user_tier' => $user->plan, // "free" | "pro" | "enterprise"
    'account_age_days' => $user->ageDays,

    // Request data
    'endpoint' => '/api/orders',
    'method' => 'POST',
    'duration_ms' => 234,

    // Business context
    'order_value' => 149.99,
    'feature_flags' => ['new-checkout', 'discount-v2'],
]);
```

### [Consistent Attribute Naming](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#consistent-attribute-naming)

Pick a naming convention and stick with it across your codebase. Inconsistent names make queries impossible.

**Recommended:** Use `snake_case` for custom attributes to match PHP conventions.

```php
// ❌ Inconsistent naming
['user' => '123']
['userId' => '123']
['user_id' => '123']
['UserID' => '123']

// ✅ Consistent snake_case
[
    'user_id' => '123',
    'order_id' => '456',
    'cart_value' => 99.99,
    'item_count' => 3,
]
```

## [Default Attributes](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#default-attributes)

The Laravel SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

### [Core Attributes](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#core-attributes)

* `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
* `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
* `sdk.name`: The name of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.name`.
* `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version`.

### [Message Template Attributes](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#message-template-attributes)

If the log was parameterized, Sentry adds the message template and parameters as log attributes.

* `message.template`: The parameterized template string. This is sent from the SDK as `sentry.message.template`.
* `message.parameter.X`: The parameters to fill the template string. X can either be the number that represent the parameter's position in the template string (`sentry.message.parameter.0`, `sentry.message.parameter.1`, etc) or the parameter's name (`sentry.message.parameter.item_id`, `sentry.message.parameter.user_id`, etc). This is sent from the SDK as `sentry.message.parameter.X`.

### [Server Attributes](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#server-attributes)

* `server.address`: The address of the server that sent the log. Equivalent to `server_name` that gets attached to Sentry errors.

### [User Attributes](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#user-attributes)

If user information is available in the current scope, the following attributes are added to the log:

* `user.id`: The user ID.
* `user.name`: The username.
* `user.email`: The email address.

### [Integration Attributes](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#integration-attributes)

If a log is generated by an SDK integration, the SDK will set additional attributes to help you identify the source of the log.

* `origin`: The origin of the log. This is sent from the SDK as `sentry.origin`.

## [Troubleshooting](https://docs.sentry.io/platforms/php/guides/laravel/logs.md#troubleshooting)

If your logs are not appearing in Sentry, check or test the following:

If you are testing in Tinker (`php artisan tinker`), make sure to call `\Sentry\logger()->flush();` manually to send Logs to Sentry as it does not trigger automatically.

Check your `config/logging.php` and ensure the default log channel and stack channel allow configuration using environment variables:

`config/logging.php`

```php
    // ...
    'default' => env('LOG_CHANNEL', 'stack'),
    // ...
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => explode(',', (string) env('LOG_STACK', 'single')),
            'ignore_exceptions' => false,
        ],
    // ...
```

Ensure that if you have defined the `LOG_LEVEL` in your `.env` file, it is set to a level that allows the logs you are expecting to be sent to Sentry.

To test your setup regardless of the Laravel configuration, you can send a test log message to Sentry with the following snippet:

```php
\Sentry\logger()->info('A test log message');
\Sentry\logger()->flush();
```

If that does not work, check your DSN configuration using `php artisan sentry:test`.
