【问题标题】:console command: log data to a specyfic file (Symfony3 and monolog)控制台命令:将数据记录到特定文件(Symfony 3 和独白)
【发布时间】: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"} []
(...)

【问题讨论】:

    标签: logging symfony monolog


    【解决方案1】:

    我相信你只需要降低你的详细程度

    documentation:

    # app/config/config.yml
    
    monolog:
        handlers:
            console:
                type:   console
                verbosity_levels:
                    VERBOSITY_NORMAL: NOTICE
                channels: sender
    

    【讨论】:

    • 感谢您的回复.. 它告诉我我应该看看其他处理程序。我创建了新的处理程序,将这些日志放到不同的文件中。
    猜你喜欢
    • 2016-06-28
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 2015-04-15
    • 2012-11-08
    • 2015-07-26
    • 1970-01-01
    • 2014-06-22
    相关资源
    最近更新 更多