Alex Rivera | Logout

custom monolog logging channel in symfony2 command

Asked 2011-10-10T15:04:52.177
15

In this cookbook article, we can see how to use a custom channel in a service. But how can I use a custom login channel in a command ?

I created a symfony2 command to perform something. I would like to use monolog to log things done by my command.

Actually, I want to write log for my command in another file than the logs of the application.

Edit
Report

1 Answer

4

Try this, use the library directly

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// ...

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('path of log file', Logger::WARNING));

//add the erros to log file

try {
    //do something
} catch(Exception $e) {
    $log->addError($e->getMessage());
}

Maybe this can resolve your problem, add this into your command file.

answered 2013-07-19T09:00:45.470

Your Answer