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

I use Symfony2 and monolog to write to specific logs in a specific log file (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 viewing the log file in my controller through:

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

Now my problem is that my log file contains the entire information layer, that is, it gives me all the logs app.INFO (this is what I want) and request.INFO (which I really do not need):

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

Is there a way to not register Request.INFO?

Mike

+7
source share
4 answers

You need to create a new registration service that should be used in your classes. For example, 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'); 

See the symfony cookie for more information.

+9
source

With version 2.4 and higher (beware, the MonologBundle release cycle no longer syncs with Symfony) MonologBundle, now you can easily define new channels through configuration without defining services.

 monolog: channels: ["my_channel"] handlers: file: type: stream path: %kernel.logs_dir%/mylogfile.log level: info channels: my_channel 

Now just get the automatically generated log for the new channel in your controller:

 $logger = $this->get('monolog.logger.my_channel'); $logger->info('somelogcontent'); 

I know an old question, but this new feature from MonologBundle ~2.4 should be mentioned.

+6
source

This log message comes from the router_listener service. You can override it in the services configuration file.

What I did in my main config / services.yml bundle:

 services: # ... router_listener: class: %router_listener.class% arguments: ['@router', %request_listener.http_port%, %request_listener.https_port%] tags: - { name: kernel.event_listener, event: kernel.request, method: onEarlyKernelRequest } - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } 

It makes the "Consistent Route ..." log messages unregistered (since the RouterListener does not have a log service in its constructor arguments).

+2
source

You can set the user alert level. file: Type: stream path:% kernel.logs_dir% / mylogfile.log Level: warning

 $logger = $this->get('logger'); // Log $logger->alert('somelogcontent'); 
+1
source

All Articles