Logging
To make our application more elegant while working in cron, we should implement logging to a file. Symfony2 supports some standard logs, through the so-called monolog component. To use this, we simply call for the logger service, and then we call the required method, either the info
, err
, debug
, notice
methods or the warn
method, as in the following example:
$logger = $this->getContainer()->get('logger'); $logger->info('Info log message');
This log message will add to the default log (development or production) depending on the environment.
We need to change this a little bit, to allow the logs to be added to a separate file.
To do this, we need to define the channel and handler. When we create a channel, a separate logger service is created, and we can use it to log information here. Creating a simple channel is easy, as we just need to pass its name into the channel's array in the config
file. After we add the channel, we need to add the handler, so that monolog would know...