Symfony monolog 系统日志格式化程序
Symfony monolog syslog formatter
是否可以为系统日志格式化日志? 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"
最后我使用了如下配置:
# 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]
是否可以为系统日志格式化日志? 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"
最后我使用了如下配置:
# 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]