Any custom command that extends ContainerAwareCommand
, has access to Symfony's service container. You can define a service that logs in a custom channel in your config.
<services>
<service id="console.logger" parent="monolog.logger_prototype">
<argument index="0">mychannel</argument>
</service>
</services>
You can access your service from the command the following way
$logger = $this->getContainer()->get('console.logger');
This logger will log with channel as "mychannel".
FYI The default logger service logs to channel "app". This can be seen in the file
Symfony/Bundle/MonologBundle/Resources/config/monolog.xml
. This is also the place where the default logger
service is defined.
<services>
<service id="monolog.logger" parent="monolog.logger_prototype" public="false">
<argument index="0">app</argument>
</service>
<service id="logger" alias="monolog.logger" />
<service id="monolog.logger_prototype" class="%monolog.logger.class%" abstract="true">
<argument /><!-- Channel -->
</service>
</services>