2015-06-15 33 views
1

我已阅读了一些文档here,但仍不清楚如何编写和使用自定义Monolog处理程序和通道。让我稍微解释一下我想达到的目标。我有一个自定义函数,我希望该日志被记录到一个名为custom.log的文件中。如何编写和使用Monolog处理程序和通道

monolog: 
    handlers: 
     #Logs Doctrine to a different channel 
     doctrine: 
      level: debug 
      type:  stream 
      path:  "%kernel.logs_dir%/doctrine.log" 
      channels: [doctrine] 

如何实现一个custom.log相同的:我已经在config.yml文件中设置启用此功能主义日志记录到另一个文件?

回答

3

你可以尝试这种方式,

monolog: 
    channels: ["testchannel"] 
    handlers: 
     test: 
      # log all messages (since debug is the lowest level) 
      level: debug 
      type:  stream 
      path:  "%kernel.logs_dir%/testchannel.log" 
      channels: ["testchannel"] 

并在控制器,你可以得到记录器和做你的事;

class DefaultController extends Controller 
{ 
    public function indexAction() 
    { 

     $logger = $this->get('monolog.logger.testchannel'); 
     $logger->info("This one goes to test channel!!"); 
     return $this->render('AcmeBundle:Default:index.html.twig'); 
    } 
} 

你也可以检查哪些独白处理程序和记录仪运行命令php app/console container:debug monolog

注册
相关问题