将 symfony 命令日志输出写入控制台和文件

mar*_*ixy 6 symfony symfony-3.4

设置如下:

我有一个命令,它调用服务 X 上使用记录器 Y 的函数。

目前,当从控制台运行时,日志消息将输出到控制台(使用参数-v)。我还想将这些消息输出到文件中,无论级别如何-v

编辑:根据要求添加独白配置(尽管没有什么有趣的 - 这是默认的)。

monolog:
    channels: ['amz_update']
    handlers:
        main:
            type: stream
            path: '%kernel.logs_dir%/%kernel.environment%.log'
            level: emergency
            channels: ['!event']
        console:
            type: console
            process_psr_3_messages: false
            channels: ['!event', '!doctrine', '!console']
        # To follow logs in real time, execute the following command:
        # `bin/console server:log -vv`
        server_log:
            type: server_log
            process_psr_3_messages: false
            host: 127.0.0.1:9911
Run Code Online (Sandbox Code Playgroud)