Skip to content

Commit 204a4cf

Browse files
Logs for Laravel (#14033)
Co-authored-by: Cursor Agent <[email protected]>
1 parent 4e3bc58 commit 204a4cf

File tree

7 files changed

+117
-7
lines changed

7 files changed

+117
-7
lines changed

docs/platforms/php/common/logs/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ sidebar_order: 5600
99

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

12-
<Alert title="Looking for Laravel or Symfony?">
12+
<Alert title="Looking for Symfony?">
1313

14-
Let us know what you would like to see on GitHub: [Laravel Logs](https://github.com/getsentry/sentry-laravel/issues/999) or [Symfony Logs](https://github.com/getsentry/sentry-symfony/issues/925).
14+
Let us know what you would like to see on GitHub: [Symfony Logs](https://github.com/getsentry/sentry-symfony/issues/925).
1515

1616
</Alert>
1717

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Set Up Logs
3+
sidebar_title: Logs
4+
description: "Structured logs allow you to send, view and query logs sent from your Laravel applications within Sentry."
5+
sidebar_order: 5600
6+
---
7+
8+
<Include name="feature-stage-beta-logs.mdx" />
9+
10+
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.
11+
12+
## Requirements
13+
14+
<PlatformContent includePath="logs/requirements" />
15+
16+
## Setup
17+
18+
<PlatformContent includePath="logs/setup" />
19+
20+
## Usage
21+
22+
<PlatformContent includePath="logs/usage" />
23+
24+
## Options
25+
26+
<PlatformContent includePath="logs/options" />

docs/product/explore/logs/getting-started/index.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
206206
label="PHP"
207207
url="/platforms/dart/guides/php/logs/"
208208
/>
209+
- <LinkWithPlatformIcon
210+
platform="php.laravel"
211+
label="Laravel"
212+
url="/platforms/php/guides/laravel/logs/"
213+
/>
209214

210215
### Python
211216

@@ -245,11 +250,6 @@ We're actively working on adding Log functionality to additional SDKs. Check out
245250
label="Elixir"
246251
url="https://github.com/getsentry/sentry-elixir/issues/886"
247252
/>
248-
- <LinkWithPlatformIcon
249-
platform="php.laravel"
250-
label="Laravel"
251-
url="https://github.com/getsentry/sentry-laravel/issues/999"
252-
/>
253253
- <LinkWithPlatformIcon
254254
platform="react-native"
255255
label="React Native"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#### before_send_log
2+
3+
To filter logs, or update them before they are sent to Sentry, you can use the `before_send_log` option.
4+
5+
```php {filename:config/sentry.php}
6+
// ...
7+
'before_send_log' => function (\Sentry\Logs\Log $log): ?\Sentry\Logs\Log {
8+
if ($log->getLevel() === \Sentry\Logs\LogLevel::info()) {
9+
// Filter out all info logs
10+
return null;
11+
}
12+
13+
return $log;
14+
},
15+
// ...
16+
]);
17+
```
18+
19+
<Alert>
20+
21+
Learn more in [Closures and Config Caching](/platforms/php/guides/laravel/configuration/laravel-options/#closures-and-config-caching).
22+
23+
</Alert>
24+
25+
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.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Logs for Laravel are supported in Sentry Laravel SDK version `4.15.0` and above.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
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.
2+
3+
```php {filename:config/logging.php}
4+
'channels' => [
5+
// ...
6+
'sentry' => [
7+
'driver' => 'sentry',
8+
],
9+
],
10+
```
11+
12+
After you configured the Sentry log channel, you can configure your app to both log to a log file and to Sentry by modifying the log stack:
13+
14+
```bash {filename:.env}
15+
# ...
16+
LOG_STACK=single,sentry
17+
# ...
18+
```
19+
20+
Optionally, you can set the logging level:
21+
22+
```php {filename:config/logging.php}
23+
'channels' => [
24+
// ...
25+
'sentry' => [
26+
'driver' => 'sentry',
27+
// The minimum logging level at which this handler will be triggered
28+
// Available levels: debug, info, notice, warning, error, critical, alert, emergency
29+
'level' => env('LOG_LEVEL', 'error'),
30+
],
31+
// ...
32+
],
33+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Once you have configured Sentry as a log channel, you can use Laravel's built-in logging functionality to send logs to Sentry:
2+
3+
```php
4+
use Illuminate\Support\Facades\Log;
5+
6+
// Log to all channels in the stack (including Sentry)
7+
Log::info('This is an info message');
8+
Log::warning('User {id} failed to login.', ['id' => $user->id]);
9+
Log::error('This is an error message');
10+
11+
// Log directly to the Sentry channel
12+
Log::channel('sentry')->error('This will only go to Sentry');
13+
```
14+
15+
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.
16+
17+
```php
18+
use Illuminate\Support\Facades\Log;
19+
20+
Log::error('Something went wrong', [
21+
'user_id' => auth()->id(),
22+
'action' => 'update_profile',
23+
'additional_data' => $data,
24+
]);
25+
```

0 commit comments

Comments
 (0)