【问题标题】:Symfony monolog syslog formatterSymfony 独白系统日志格式化程序
【发布时间】:2018-09-26 08:56:48
【问题描述】:

是否可以为 syslog 格式化日志?配置系统日志的config.yml:

monolog:
    channels: ['auth']
    handlers:    
    auth:
        type: syslog
        level: debug
        facility: local0
        channels: [auth]

出现警告时打印的结果行:

Sep 20 15:43:31 api2 [10227]: auth.WARNING: invalid password {"method":"ApiBundle\\Api.....

我想看到的那条线:

Sep 20 15:43:31 api2 auth.WARNING[10227]: invalid password {"method":"ApiBundle\\Api.....

我尝试使用格式化程序,但没有成功:

# config.yml
monolog:
    ...
    handlers:
    auth:
        ...
        formatter: monolog.formatter.auth_exception

# services.yml
monolog.formatter.auth_exception:
    class: Monolog\Formatter\LineFormatter
    arguments:
        - "[%%datetime%%] %%channel%%.%%level_name%%: %%message%% %%context%% %%extra%%\n"

【问题讨论】:

  • 你的格式化程序在哪里?你的格式化程序是实现 Monolog\Formatter\FormatterInterface
  • Monolog\Formatter\LineFormatter 是 Monolog 的内置 Formatter
  • @paddel10 这个问题你解决了吗?
  • @nssmart 请在下面查看我的回答。希望这会有所帮助

标签: php symfony syslog monolog


【解决方案1】:

最后我使用了以下配置:

# config.yml
monolog:
    channels: ['weather', 'auth']
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      syslog_handler
        syslog_handler:
            type: syslog
            level: debug
        console:
            type:  console
        app:
            type: syslog
            level: debug
            channels: ['weather']
        auth:
            type: syslog
            level: warning
            facility: auth
            channels: [auth]

【讨论】:

    猜你喜欢
    • 2015-01-22
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多