Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when setting up null handler with symfony & YAML #284

Closed
dinbrca opened this issue Oct 31, 2018 · 3 comments
Closed

Problem when setting up null handler with symfony & YAML #284

dinbrca opened this issue Oct 31, 2018 · 3 comments
Labels
Milestone

Comments

@dinbrca
Copy link

dinbrca commented Oct 31, 2018

As defined in here:
https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/Configuration.php#L25
A developer can user null handler to send logs to no where (obvious usage is testing purposes).

The problem comes when trying to use it in Symfony and YAML.
As stated in the Symfony Docs, adding an handler is as follow (from the docs - https://symfony.com/doc/current/logging.html):

# config/packages/prod/monolog.yaml
monolog:
    handlers:
        # this "file_log" key could be anything
        file_log:
            type: stream
            # log to var/log/(environment).log
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            # log *all* messages (debug is lowest level)
            level: debug

        syslog_handler:
            type: syslog
            # log error-level messages and higher
            level: error

The problem comes when you try to add a null logger as following:

# config/packages/prod/monolog.yaml
monolog:
    handlers:
        # this "file_log" key could be anything
        file_log:
            type: stream
            # log to var/log/(environment).log
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            # log *all* messages (debug is lowest level)
            level: debug

        syslog_handler:
            type: syslog
            # log error-level messages and higher
            level: error

        null_log:
            type: null
            level: debug

because null is unavailable when using YAML, YAML will parse it as following and retrieve an error to developer:

vagrant@homestead:/srv/www/backend-mallabee$ php /srv/www/backend-mallabee/bin/console mallabee:mp_monitor_sync all
string(6) "stream"
string(6) "stream"
string(7) "console"
string(6) "loggly"
string(5) "raven"
string(0) ""

In MonologExtension.php line 795:
                                                     
  There is no handler class defined for handler "".  

This is fixed by adding a quotation to the null handler in it's type as follow:

# config/packages/prod/monolog.yaml
monolog:
    handlers:
        # this "file_log" key could be anything
        file_log:
            type: stream
            # log to var/log/(environment).log
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            # log *all* messages (debug is lowest level)
            level: debug

        syslog_handler:
            type: syslog
            # log error-level messages and higher
            level: error

        null_log:
            type: "null"
            level: debug

The problem is that it's not so obvious that you need to add the quotation until you get bumped into it because the docs doesn't add quotation.

@Seldaek Seldaek added the Bug label Dec 26, 2018
@Seldaek Seldaek added this to the 3.3 milestone Dec 26, 2018
@Seldaek
Copy link
Member

Seldaek commented Dec 26, 2018

I agree it's not a nice UX.. will have to see if we can detect it and warn.

@gggeek
Copy link

gggeek commented Mar 29, 2021

FYI: I am on symfony/yaml v5.1.11, and with that version, even using a quoted 'null' string in the yaml config is not working...

edit: nvm, not true. pebkac

@gggeek
Copy link

gggeek commented Mar 29, 2021

ps: what about adding an alias which is easier not to miscast? eg 'none'

edit: lol, I just found out that this is a problem with XML config, too, and that it was suggested as well in #133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants