如何配置rsyslog与SysLogHandler日志记录类一起使用? [英] How to configure rsyslog for use with SysLogHandler logging class?

查看:138
本文介绍了如何配置rsyslog与SysLogHandler日志记录类一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了将"myapp"的日志消息写入/var/log/local5.log,我使用

In order to write log messages of "myapp" into /var/log/local5.log, I use SysLogHandler.

"myapp"运行良好,没有错误,但未记录任何内容,/var/log/local5.log仍然为空.

"myapp" runs well, no error, but nothing gets logged, /var/log/local5.log remains empty.

日志记录配置文件的相关部分:

Relevant parts of the logging configuration file:

handlers:
    mainHandler:
        class: logging.handlers.SysLogHandler
        level: INFO
        formatter: defaultFormatter
        address: '/dev/log'
        facility: 'local5'

loggers:
    __main__:
        level: INFO
        handlers: [mainHandler]

记录测试

这是我尝试在"myapp"主脚本中编写日志的方法:

logging test

Here is how I try to write a log in the main script of "myapp":

with open('myconfig.yml') as f:
    logging.config.dictConfig(yaml.load(f))

log = logging.getLogger(__name__)
log.info("Starting")

我在/usr/lib/python3.4/logging/handlers.py中添加了一些sys.stderr.write()以查看发生了什么,然后我得到了:

I have added some sys.stderr.write() to /usr/lib/python3.4/logging/handlers.py to see what's happening and I get:

$ myapp
[SysLogHandler._connect_unixsocket()] Sucessfully connected to socket: /dev/log
[SysLogHandler.emit()] called
[SysLogHandler.emit()] msg=b'<174>2016/04/23 07:17:00.453 myapp: main: Starting\x00'
[SysLogHandler.emit()] msg sent to unix socket (no OSError)

rsyslog配置

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆