Search code examples
symfonymonolog

Symfony2/Monolog: Log Level - only show app.INFO?


I am using Symfony2 and monolog to write in specific logs in a defined logfile (mylogfile.log):

#config_dev.yml
monolog:
    handlers:
        main:
           type:  stream
           path:  %kernel.logs_dir%/%kernel.environment%.log
           level: debug
       file:
           type:   stream
           path:   %kernel.logs_dir%/mylogfile.log
           level:  info

I am accessing the logfile in my controller via:

    $logger = $this->get('logger'); // Log
    $logger->info('somelogcontent');

Now my issue is that my log file contains the whole info level, meaning it gives me all app.INFO logs (which is what I want) and request.INFO (which I don't really need):

[2012-04-04 11:13:17] request.INFO: Matched route ... blablabla
[2012-04-04 11:13:17] app.INFO: somelogcontent
...

Is there any way not to log the Request.INFO?

Mike


Solution

  • You have to make a new logger service, which should be used it in your classes. Like this, config.yml:

    services:
      my_logger:
        class: Monolog\Logger
        arguments: [my_info]
        calls:
            - [pushHandler, [@my_log_handler]]
    
      my_log_handler:
        class: Monolog\Handler\StreamHandler
        arguments: [%kernel.root_dir%/logs/my_info.log, 100]
    

    Usage (in Controller, for example):

    $this->get('my_logger')->info('info message');
    

    More detailed information in symfony cookbook.