I am working on a Symfony 2 web application and I would like to introduce a Monolog logger using a dedicated channel for the service:
Configuration:
monolog: handlers: main: type: stream path: %kernel.root_dir%/%kernel.environment%.log level: error
Service Config:
services: some_service: class: Some\Service arguments: [@logger] tags: - { name: monolog.logger, channel: alert }
Service:
class SomeService { protected $logger; public function __construct($logger) { $this->logger = $logger; $this->logger->info('Log this!'); }
Prod.log file:
[2016-03-28 11:25:47] alert.INFO: Register!
Problem:. Although I specifically add a registrar using the alert
channel, the message is processed by the main
handler. Thus, messages are written to the prod.log
file instead of the prod.alert.log
file.
When I leave the line channels: [!alert]
as a comment, the message is logged on prod.log
. When I activate this line by deleting the comment, the message is not logged at all (the main handler correctly ignores the channel).
What do I need to use a specific handler to target a specific log file, email program, etc.? Messages in the alert
channel must be handled by the alert
handler, while all other handlers are ignored.
source share