我想将控制器的日志记录在新的日志文件中

问题描述 投票:0回答:1

在 Symfony 5.4 中,并使用 monolog 3.8。我想在新的日志文件中记录特定控制器的请求处理。对于我的情况是城市控制器 这是我的独白配置。

monolog:
    channels:
        - deprecation 
        - cities_controller

when@dev:
    monolog:
        handlers:
            main:
                type: stream
                path: "%kernel.logs_dir%/%kernel.environment%.log"
                level: debug
                channels: ["!event"]
            # uncomment to get logging in your browser
            # you may have to allow bigger header sizes in your Web server configuration
            #firephp:
            #    type: firephp
            #    level: info
            #chromephp:
            #    type: chromephp
            #    level: info
            cities_controller_log:
                type: stream
                path: "%kernel.logs_dir%/CitiesController.log"
                level: debug
                channels: ['cities_controller']
            console:
                type: console
                process_psr_3_messages: false
                channels: ["!event", "!doctrine", "!console"]
           

我希望将城市控制器的日志保存在一个名为cityController.log的新文件中 但据我检查,日志文件并未创建。 我在 var/dev.logs 中获取日志

php symfony monolog
1个回答
0
投票

尝试此配置,也许您不在 dev 环境中:

monolog:
    channels:
        - deprecation 
        - cities_controller

    handlers:
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            channels: ["!event"]

        cities_controller_log:
            type: stream
            path: "%kernel.logs_dir%/CitiesController.log"
            level: debug
            channels: ['cities_controller']

        console:
            type: console
            process_psr_3_messages: false
            channels: ["!event", "!doctrine", "!console"]
© www.soinside.com 2019 - 2024. All rights reserved.