symfony 2中的频道是什么?

时间:2012-08-03 16:27:12

标签: php symfony

我正在尝试使用以下日志记录机制:

log_handler:
    class: %monolog.handler.stream.class%
    arguments: [ %kernel.logs_dir%/%kernel.environment%.yourFileName.log ]


logger:
class: %monolog.logger.class%
    arguments: [ nameOfLoggingChannel ]
    calls: [ [pushHandler, [@log_handler]] ]

然而我的应用程序正在解析“nameOfLoggingChannel”。那是什么?有人可以提供一些指导吗?

1 个答案:

答案 0 :(得分:2)

这只是一个名字。它将包含在该记录器记录的消息中。引自the docs

  

频道是识别记录与应用程序的哪个部分相关的好方法。这在大型应用程序中很有用(并且在Symfony2中由MonologBu​​ndle使用)。然后,您可以轻松地浏览日志文件,例如过滤此类型或该类型的日志记录。

     

使用具有相同处理程序的不同记录器允许通过保持相同的处理程序(例如使用单个日志文件)来识别发出记录的记录器(通过通道名称)。

<?php

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

// Create some handlers
$stream = new StreamHandler(__DIR__.'/my_app.log', Logger::DEBUG);
$firephp = new FirePHPHandler();

// Create the main logger of the app
$logger = new Logger('my_logger');
$logger->pushHandler($stream);
$logger->pushHandler($firephp);

// Create a logger for the security-related stuff with a different channel
$securityLogger = new Logger('security');
$securityLogger->pushHandler($stream);
$securityLogger->pushHandler($firephp);