|
6 | 6 |
|
7 | 7 | use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
|
8 | 8 | use Jean85\PrettyVersions;
|
9 |
| -use LogicException; |
| 9 | +use Monolog\Logger as MonologLogger; |
10 | 10 | use Psr\Log\NullLogger;
|
11 | 11 | use Sentry\Client;
|
12 | 12 | use Sentry\ClientBuilder;
|
13 | 13 | use Sentry\Integration\IgnoreErrorsIntegration;
|
14 | 14 | use Sentry\Integration\IntegrationInterface;
|
15 | 15 | use Sentry\Integration\RequestFetcherInterface;
|
16 | 16 | use Sentry\Integration\RequestIntegration;
|
| 17 | +use Sentry\Monolog\Handler; |
17 | 18 | use Sentry\Options;
|
18 | 19 | use Sentry\SentryBundle\EventListener\ConsoleListener;
|
19 | 20 | use Sentry\SentryBundle\EventListener\ErrorListener;
|
|
32 | 33 | use Symfony\Component\Config\FileLocator;
|
33 | 34 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
34 | 35 | use Symfony\Component\DependencyInjection\Definition;
|
| 36 | +use Symfony\Component\DependencyInjection\Exception\LogicException; |
35 | 37 | use Symfony\Component\DependencyInjection\Loader;
|
36 | 38 | use Symfony\Component\DependencyInjection\Reference;
|
37 | 39 | use Symfony\Component\ErrorHandler\Error\FatalError;
|
@@ -70,6 +72,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
|
70 | 72 | $this->registerDbalTracingConfiguration($container, $mergedConfig['tracing']);
|
71 | 73 | $this->registerTwigTracingConfiguration($container, $mergedConfig['tracing']);
|
72 | 74 | $this->registerCacheTracingConfiguration($container, $mergedConfig['tracing']);
|
| 75 | + $this->registerMonologHandlerConfiguration($container, $mergedConfig['monolog']); |
73 | 76 | }
|
74 | 77 |
|
75 | 78 | /**
|
@@ -236,6 +239,28 @@ private function registerCacheTracingConfiguration(ContainerBuilder $container,
|
236 | 239 | $container->setParameter('sentry.tracing.cache.enabled', $isConfigEnabled);
|
237 | 240 | }
|
238 | 241 |
|
| 242 | + /** |
| 243 | + * @param array<string, mixed> $config |
| 244 | + */ |
| 245 | + private function registerMonologHandlerConfiguration(ContainerBuilder $container, array $config): void |
| 246 | + { |
| 247 | + $errorHandlerConfig = $config['error_handler']; |
| 248 | + |
| 249 | + if (!$errorHandlerConfig['enabled']) { |
| 250 | + $container->removeDefinition(Handler::class); |
| 251 | + |
| 252 | + return; |
| 253 | + } |
| 254 | + |
| 255 | + if (!class_exists(MonologLogger::class)) { |
| 256 | + throw new LogicException(sprintf('To use the "%s" class you need to require the "symfony/monolog-bundle" package.', Handler::class)); |
| 257 | + } |
| 258 | + |
| 259 | + $definition = $container->getDefinition(Handler::class); |
| 260 | + $definition->setArgument(0, MonologLogger::toMonologLevel($config['level'])); |
| 261 | + $definition->setArgument(1, $config['bubble']); |
| 262 | + } |
| 263 | + |
239 | 264 | /**
|
240 | 265 | * @param string[] $integrations
|
241 | 266 | * @param array<string, mixed> $config
|
|
0 commit comments