Skip to content

Commit b9d3b3a

Browse files
committed
Merge branch '3.x' into 4.x
* 3.x: Support null for the NullHandler
2 parents cb785de + 58ff90b commit b9d3b3a

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
@@ -403,10 +403,9 @@ public function getConfigTreeBuilder(): TreeBuilder
403403
->children()
404404
->scalarNode('type')
405405
->isRequired()
406-
->treatNullLike('null')
407406
->beforeNormalization()
408-
->always()
409-
->then(function ($v) { return strtolower($v); })
407+
->ifString()->then(function ($v) { return strtolower($v); })
408+
->ifNull()->then(function ($v) { return 'null'; })
410409
->end()
411410
->end()
412411
->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 Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
1718
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -243,6 +244,16 @@ public function testNativeMailer()
243244
$this->assertSame(['addHeader', [['Foo: bar', 'Baz: inga']]], $methodCalls[1]);
244245
}
245246

247+
public function testTypeNull()
248+
{
249+
$container = $this->getContainer('type_null');
250+
251+
$logger = $container->getDefinition('monolog.handler.null_handler');
252+
253+
$this->assertSame(NullHandler::class, $logger->getClass());
254+
$this->assertSame('DEBUG', $logger->getArgument(0));
255+
}
256+
246257
protected function getContainer($fixture): ContainerBuilder
247258
{
248259
$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)