I want to write my application logs in another file than the one Symfony2 writes its own logs and system logs. I understood that I needed to create a service of my own like this :
services:
actionslogger:
class: Symfony\Bridge\Monolog\Logger
arguments: [app]
calls:
- [pushHandler, [@actionslogger_handler]]
actionslogger_handler:
class: Monolog\Handler\StreamHandler
arguments: [%kernel.logs_dir%/actions_%kernel.environment%.log, 200]
That works fine when I use $logger = $this->get('actionslogger'); in my application, so that's ok. But I also want to use a Formatter and a Processor to manage the way my logs are written. To do that, I use this configuration :
services:
actionslogger.formatter.session_request:
class: Monolog\Formatter\LineFormatter
arguments:
- "[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%%\n"
actionslogger.processor.session_request:
class: My\Bundle\LogProcessor
arguments: [ @session ]
tags:
- { name: actionslogger.processor, method: processRecord }
I can use this Formatter and Processor with Symfony2 default logger with this config:
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
formatter: actionslogger.formatter.session_request
But if I can use the Formatter with my own logger, I can't use the Processor. Here's my config:
services:
actionslogger.formatter.session_request:
class: Monolog\Formatter\LineFormatter
arguments:
- "[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%%\n"
actionslogger.processor.session_request:
class: My\Bundle\LogProcessor
arguments: [ @session ]
tags:
- { name: actionslogger.processor, channel: app, method: processRecord, handler: @actionslogger_handler }
actionslogger:
class: Symfony\Bridge\Monolog\Logger
arguments: [app]
calls:
- [pushHandler, [@actionslogger_handler]]
actionslogger_handler:
class: Monolog\Handler\StreamHandler
arguments: [%kernel.logs_dir%/actions_%kernel.environment%.log, 200]
calls:
#- [pushProcessor, [???]]
- [setFormatter, [@actionslogger.formatter.session_request]]
The tags channel and handler in the Processor's config seems useless.
What can I do to make the Processor work with my logger? What should I pass to the pushProcessor method in the commented line (if that could be a valid option)?
Thanks for the help.
Note: using Symfony 2.0.0