Skip to content

Commit

Permalink
Remove the config section related to Monolog
Browse files Browse the repository at this point in the history
  • Loading branch information
ste93cry committed Jan 6, 2021
1 parent 7f82f1c commit 051c42a
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 183 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- PHP 8 support (#399, thanks to @Yozhef)
- Retrieve the request from the `RequestStack` when using the `RequestIntegration` integration (#361)
- Reorganize the folder structure and change CS standard (#405)
- [BC BREAK] Removed the `monolog` configuration option. Instead, register the service manually (#406)

## 3.5.3 (2020-10-13)

Expand Down
23 changes: 22 additions & 1 deletion UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@

- Removed the `ClientBuilderConfigurator` class.
- Removed the `SentryBundle::getSdkVersion()` method.
- Removed `SentryBundle::getCurrentHub()` method, use `SentrySdk::getCurrentHub()` instead.
- Removed the `SentryBundle::getCurrentHub()` method, use `SentrySdk::getCurrentHub()` instead.
- Removed the `Sentry\ClientBuilderInterface` and `Sentry\Options` services.
- Refactorized the `ErrorTypesParser` class and made it `@internal`.
- Removed the `sentry.monolog` configuration option.

Before

```yaml
sentry:
monolog:
level: !php/const Monolog\Logger::ERROR
bubble: false
```

After

```yaml
services:
Sentry\Monolog\Handler:
arguments:
$hub: Sentry\State\HubInterface
$level: !php/const Monolog\Logger::ERROR
$bubble: false
```
22 changes: 0 additions & 22 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sentry\SentryBundle\DependencyInjection;

use Jean85\PrettyVersions;
use Monolog\Logger;
use Sentry\Options;
use Sentry\SentryBundle\ErrorTypesParser;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
Expand Down Expand Up @@ -128,7 +127,6 @@ public function getConfigTreeBuilder(): TreeBuilder
;

$this->addMessengerSection($rootNode);
$this->addMonologSection($rootNode);
$this->addListenerSection($rootNode);

return $treeBuilder;
Expand All @@ -147,26 +145,6 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode): void
->end();
}

private function addMonologSection(ArrayNodeDefinition $rootNode): void
{
$rootNode
->children()
->arrayNode('monolog')
->addDefaultsIfNotSet()
->children()
->arrayNode('error_handler')
->{class_exists(Logger::class) ? 'canBeDisabled' : 'canBeEnabled'}()
->end()
->scalarNode('level')
->defaultValue(Logger::DEBUG)
->cannotBeEmpty()
->end()
->booleanNode('bubble')->defaultTrue()->end()
->end()
->end()
->end();
}

private function addListenerSection(ArrayNodeDefinition $rootNode): void
{
$rootNode
Expand Down
26 changes: 0 additions & 26 deletions src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
namespace Sentry\SentryBundle\DependencyInjection;

use Jean85\PrettyVersions;
use Monolog\Logger as MonologLogger;
use Sentry\Client;
use Sentry\ClientBuilder;
use Sentry\Integration\IgnoreErrorsIntegration;
use Sentry\Integration\IntegrationInterface;
use Sentry\Integration\RequestFetcherInterface;
use Sentry\Integration\RequestIntegration;
use Sentry\Monolog\Handler;
use Sentry\Options;
use Sentry\SentryBundle\EventListener\ErrorListener;
use Sentry\SentryBundle\EventListener\MessengerListener;
Expand All @@ -23,7 +21,6 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ErrorHandler\Error\FatalError;
Expand Down Expand Up @@ -62,7 +59,6 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
$this->registerConfiguration($container, $mergedConfig);
$this->registerErrorListenerConfiguration($container, $mergedConfig);
$this->registerMessengerListenerConfiguration($container, $mergedConfig['messenger']);
$this->registerMonologHandlerConfiguration($container, $mergedConfig['monolog']);
}

/**
Expand Down Expand Up @@ -155,28 +151,6 @@ private function registerMessengerListenerConfiguration(ContainerBuilder $contai
$container->getDefinition(MessengerListener::class)->setArgument(1, $config['capture_soft_fails']);
}

/**
* @param array<string, mixed> $config
*/
private function registerMonologHandlerConfiguration(ContainerBuilder $container, array $config): void
{
$errorHandlerConfig = $config['error_handler'];

if (!$errorHandlerConfig['enabled']) {
$container->removeDefinition(Handler::class);

return;
}

if (!class_exists(MonologLogger::class)) {
throw new LogicException(sprintf('To use the "%s" class you need to require the "symfony/monolog-bundle" package.', Handler::class));
}

$definition = $container->getDefinition(Handler::class);
$definition->setArgument(0, MonologLogger::toMonologLevel($config['level']));
$definition->setArgument(1, $config['bubble']);
}

/**
* @param string[] $integrations
* @param array<string, mixed> $config
Expand Down
45 changes: 0 additions & 45 deletions src/Resources/config/schema/sentry-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<xsd:element name="options" type="options" minOccurs="0" maxOccurs="1" />
<xsd:element name="messenger" type="messenger" minOccurs="0" maxOccurs="1" />
<xsd:element name="listener-priorities" type="listeners-priorities" minOccurs="0" maxOccurs="1" />
<xsd:element name="monolog" type="monolog" minOccurs="0" maxOccurs="1" />
</xsd:choice>

<xsd:attribute name="register-error-listener" type="xsd:boolean" />
Expand Down Expand Up @@ -90,48 +89,4 @@
<xsd:attribute name="console-terminate" type="xsd:integer" />
<xsd:attribute name="worker-error" type="xsd:integer" />
</xsd:complexType>

<xsd:complexType name="monolog">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="error-handler" type="monolog-error-handler" minOccurs="0" maxOccurs="1" />
</xsd:choice>

<xsd:attribute name="level" type="monolog-level" />
<xsd:attribute name="bubble" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name="monolog-error-handler">
<xsd:attribute name="enabled" type="xsd:boolean" />
</xsd:complexType>

<xsd:simpleType name="monolog-level">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="debug" />
<xsd:enumeration value="info" />
<xsd:enumeration value="notice" />
<xsd:enumeration value="warning" />
<xsd:enumeration value="error" />
<xsd:enumeration value="critical" />
<xsd:enumeration value="alert" />
<xsd:enumeration value="emergency" />

<xsd:enumeration value="DEBUG" />
<xsd:enumeration value="INFO" />
<xsd:enumeration value="NOTICE" />
<xsd:enumeration value="WARNING" />
<xsd:enumeration value="ERROR" />
<xsd:enumeration value="CRITICAL" />
<xsd:enumeration value="ALERT" />
<xsd:enumeration value="EMERGENCY" />

<xsd:enumeration value="100" />
<xsd:enumeration value="200" />
<xsd:enumeration value="250" />
<xsd:enumeration value="300" />
<xsd:enumeration value="400" />
<xsd:enumeration value="500" />
<xsd:enumeration value="550" />
<xsd:enumeration value="600" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
4 changes: 0 additions & 4 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
<tag name="console.command" />
</service>

<service id="Sentry\Monolog\Handler" class="Sentry\Monolog\Handler">
<argument type="service" id="Sentry\State\HubInterface" />
</service>

<service id="Sentry\Integration\RequestFetcherInterface" class="Sentry\SentryBundle\Integration\RequestFetcher">
<argument type="service" id="Symfony\Component\HttpFoundation\RequestStack" />
<argument type="service">
Expand Down
8 changes: 0 additions & 8 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sentry\SentryBundle\Tests\DependencyInjection;

use Jean85\PrettyVersions;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Sentry\SentryBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
Expand Down Expand Up @@ -35,13 +34,6 @@ public function testProcessConfigurationWithDefaultConfiguration(): void
'enabled' => interface_exists(MessageBusInterface::class),
'capture_soft_fails' => true,
],
'monolog' => [
'error_handler' => [
'enabled' => class_exists(Logger::class),
],
'level' => Logger::DEBUG,
'bubble' => true,
],
'register_error_listener' => true,
'listener_priorities' => [
'request' => 1,
Expand Down
14 changes: 0 additions & 14 deletions tests/DependencyInjection/Fixtures/php/monolog_handler.php

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions tests/DependencyInjection/Fixtures/xml/monolog_handler.xml

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions tests/DependencyInjection/Fixtures/yml/monolog_handler.yml

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
namespace Sentry\SentryBundle\Tests\DependencyInjection;

use Jean85\PrettyVersions;
use Monolog\Logger as MonologLogger;
use PHPUnit\Framework\TestCase;
use Sentry\ClientInterface;
use Sentry\Integration\IgnoreErrorsIntegration;
use Sentry\Monolog\Handler;
use Sentry\Options;
use Sentry\SentryBundle\DependencyInjection\SentryExtension;
use Sentry\SentryBundle\EventListener\ConsoleCommandListener;
Expand Down Expand Up @@ -266,22 +264,6 @@ public function subRequestListenerDataProvider(): \Generator
];
}

public function testMonologHandler(): void
{
$container = $this->createContainerFromFixture('monolog_handler');
$definition = $container->getDefinition(Handler::class);

$this->assertSame(MonologLogger::ERROR, $definition->getArgument(0));
$this->assertFalse($definition->getArgument(1));
}

public function testMonologHandlerIsRemovedWhenDisabled(): void
{
$container = $this->createContainerFromFixture('monolog_handler_disabled');

$this->assertFalse($container->hasDefinition(Handler::class));
}

public function testClentIsCreatedFromOptions(): void
{
$container = $this->createContainerFromFixture('full');
Expand Down

0 comments on commit 051c42a

Please sign in to comment.