Skip to content

Commit 6a51dbe

Browse files
authored
Auto configure our log channels (#1042)
1 parent 7838696 commit 6a51dbe

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

config/sentry.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#enable_logs
3636
'enable_logs' => env('SENTRY_ENABLE_LOGS', false),
3737

38+
// The minimum log level that will be sent to Sentry as logs using the `sentry_logs` logging channel
39+
'logs_channel_level' => env('SENTRY_LOGS_LEVEL', env('LOG_LEVEL', 'debug')),
40+
3841
// @see: https://docs.sentry.io/platforms/php/guides/laravel/configuration/options/#send_default_pii
3942
'send_default_pii' => env('SENTRY_SEND_DEFAULT_PII', false),
4043

src/Sentry/Laravel/ServiceProvider.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Sentry\Laravel;
44

5+
use Illuminate\Contracts\Config\Repository;
56
use Illuminate\Contracts\Container\BindingResolutionException;
67
use Illuminate\Contracts\Events\Dispatcher;
78
use Illuminate\Contracts\Http\Kernel as HttpKernelInterface;
@@ -44,6 +45,8 @@ class ServiceProvider extends BaseServiceProvider
4445
'breadcrumbs',
4546
// We resolve the integrations through the container later, so we initially do not pass it to the SDK yet
4647
'integrations',
48+
// We have this setting to allow us to capture the .env LOG_LEVEL for the sentry_logs channel
49+
'logs_channel_level',
4750
// This is kept for backwards compatibility and can be dropped in a future breaking release
4851
'breadcrumbs.sql_bindings',
4952

@@ -134,6 +137,8 @@ public function register(): void
134137
$this->configureAndRegisterClient();
135138

136139
$this->registerFeatures();
140+
141+
$this->registerLogChannels();
137142
}
138143

139144
/**
@@ -185,6 +190,29 @@ protected function registerFeatures(): void
185190
}
186191
}
187192

193+
/**
194+
* Register the log channels.
195+
*/
196+
protected function registerLogChannels(): void
197+
{
198+
$config = $this->app->make(Repository::class);
199+
200+
$logChannels = $config->get('logging.channels', []);
201+
202+
if (!array_key_exists('sentry', $logChannels)) {
203+
$config->set('logging.channels.sentry', [
204+
'driver' => 'sentry',
205+
]);
206+
}
207+
208+
if (!array_key_exists('sentry_logs', $logChannels)) {
209+
$config->set('logging.channels.sentry_logs', [
210+
'driver' => 'sentry_logs',
211+
'level' => $config->get('sentry.logs_channel_level', 'debug'),
212+
]);
213+
}
214+
}
215+
188216
/**
189217
* Boot all the features.
190218
*/

0 commit comments

Comments
 (0)