【发布时间】:2017-02-20 11:56:14
【问题描述】:
我有一个控制台命令作为服务。 我想记录下,该命令是在一个名为 foo.log 的日志文件中执行的 - 并且没有其他日志要放置在那里。
我几乎完成了,但是:
在案例A中,我将所有日志都保存到我的特定文件中(不仅仅是我想要的)
在 case B 中,我将我的特定日志保存到 foo.log 文件中,但是当运行 consol 命令时,我会在控制台屏幕上看到其他日志。
命令文件
class A extends command
{
(...)
protected function execute(InputInterface $input, OutputInterface $output)
{
(...)
$this->logger->info('done it');
}
}
services.yml
sender.command.fetch.and.send:
class: ReportsBundle\Command\SendReports
arguments:
- "@sender.reports.worker"
- "@logger"
tags:
- { name: console.command }
- { name: monolog.logger, channel: sender}
case A (config.yml) - 当我将所有日志都写入 foo.log
monolog:
handlers:
sender:
type: stream
path: '%kernel.logs_dir%/foo.log'
channels: ~
案例 B (config.yml) 当我在屏幕上看到不需要的日志时
monolog:
channels: ['sender']
handlers:
sender:
type: stream
path: '%kernel.logs_dir%/foo.log'
channels: sender
不需要的日志:
(...)
[2016-10-11 20:48:28] doctrine.DEBUG: SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED [] []
[2016-10-11 20:48:28] doctrine.DEBUG: [] []
[2016-10-11 20:48:28] event.DEBUG: Notified event "{event}" to listener "{listener}". {"event":"console.exception","listener":"Staffim\\RollbarBundle\\EventListener\\RollbarListener::onConsoleException"} []
(...)
【问题讨论】: