monolog-bundle icon indicating copy to clipboard operation
monolog-bundle copied to clipboard

Cannot use the NullHandler with XML configuration

Open v1nc3n4 opened this issue 9 years ago • 9 comments

Hi,

I'm working on a Symfony 2 application, and I'd like to temporary disable logging. I found that adding the NullHandler on top of the configured handlers shall do the job. Here's my monolog XML configuration:

<monolog:config>
    <monolog:handler name="null_handler" type="null" />
    <monolog:handler name="file_handler" type="stream" level="info" path="%kernel.logs_dir%/%kernel.environment%.log" />
</monolog:config>

However, when I access a web page, this error occured:

InvalidArgumentException in MonologExtension.php line 611:
Invalid handler type "" given for handler "null_handler"

It seems the null type in the XML parameter is treated as a blank string, and I guess there may be an issue in the Configuration class of the bundle. What is your opinion?

Thanks for your help, BR

v1nc3n4 avatar Jun 24 '15 08:06 v1nc3n4

It is not treated as an empty string, but as null

stof avatar Jun 24 '15 08:06 stof

Yes indeed.

v1nc3n4 avatar Jun 24 '15 08:06 v1nc3n4

I don't know if we can do much about this, given XML is string only it will always be normalized after..

Seldaek avatar Jun 24 '15 09:06 Seldaek

What about changing the key for the NullHandler or renaming it? for instance:

<monolog:config>
    <monolog:handler name="nolog_handler" type="nolog" />
</monolog:config>

v1nc3n4 avatar Jun 24 '15 12:06 v1nc3n4

I'd rather not change it but maybe we can have an alias as workaround for xml.

Seldaek avatar Jun 24 '15 14:06 Seldaek

what about BlackHole? faced same issue today.

jaymecd avatar Sep 03 '15 13:09 jaymecd

I would go with null_handler to keep the same semantics. Do someone want to submit a PR?

lyrixx avatar May 18 '19 13:05 lyrixx

null_handler is fine with me, but the fact that the handler never bubbles makes it in fact behave more similar to what I'd expect from a "black hole" (see #399 for more about this issue)

gggeek avatar Mar 29 '21 10:03 gggeek

Pr sent: https://github.com/symfony/monolog-bundle/pull/400

gggeek avatar Mar 29 '21 10:03 gggeek