Skip to content

Commit 047ba44

Browse files
committed
Support null for the NullHandler
1 parent f78fcaf commit 047ba44

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,9 @@ public function getConfigTreeBuilder(): TreeBuilder
451451
->children()
452452
->scalarNode('type')
453453
->isRequired()
454-
->treatNullLike('null')
455454
->beforeNormalization()
456-
->always()
457-
->then(function ($v) { return strtolower($v); })
455+
->ifString()->then(function ($v) { return strtolower($v); })
456+
->ifNull()->then(function ($v) { return 'null'; })
458457
->end()
459458
->end()
460459
->scalarNode('id')->end() // service & rollbar

tests/DependencyInjection/FixtureMonologExtensionTestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
1515
use Monolog\Handler\NoopHandler;
16+
use Monolog\Handler\NullHandler;
1617
use Monolog\Processor\PsrLogMessageProcessor;
1718
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
1819
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
@@ -312,6 +313,16 @@ public function testNativeMailer()
312313
$this->assertSame(['addHeader', [['Foo: bar', 'Baz: inga']]], $methodCalls[1]);
313314
}
314315

316+
public function testTypeNull()
317+
{
318+
$container = $this->getContainer('type_null');
319+
320+
$logger = $container->getDefinition('monolog.handler.null_handler');
321+
322+
$this->assertSame(NullHandler::class, $logger->getClass());
323+
$this->assertSame('DEBUG', $logger->getArgument(0));
324+
}
325+
315326
protected function getContainer($fixture)
316327
{
317328
$container = new ContainerBuilder();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
7+
8+
<monolog:config>
9+
<monolog:handler
10+
name="null_handler"
11+
type="null" />
12+
</monolog:config>
13+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
monolog:
2+
handlers:
3+
null_handler:
4+
type: null

0 commit comments

Comments
 (0)