[英]How to configure syslog for logging in Python
I have started to use logging module in python. 我已经开始在python中使用日志记录模块。 My python code properly logs via several handlers but in my code I still use also syslog module.
我的python代码通过几个处理程序正确记录,但在我的代码中我仍然使用syslog模块。 When I tried to replace it and add just another handler to logging, I found out that output differs.
当我尝试替换它并仅添加另一个处理程序来记录时,我发现输出不同。
logging.handlers.SysLogHandler(address = "/dev/log")
...
logging.error("Foo")
syslog.syslog(syslog.LOG_ERR, "Foo")
The output is: 输出是:
Apr 14 16:42:33 hroch journal: Foo
Apr 2 10:11:51 hroch myscript: Unable to connect/login to fencing device
Attempt to use logging.Formatter did not bring any success as only part after colon is changed. 尝试使用logging.Formatter没有带来任何成功,因为只有部分冒号后更改。
The address=
parameter to SysLogHandler() should be a (host, port) tuple. SysLogHandler()的
address=
参数应该是(主机,端口)元组。 Try leaving it off; 试着把它关掉; the default is
('localhost', SYSLOG_UDP_PORT)
, which might be what you want. 默认值是
('localhost', SYSLOG_UDP_PORT)
,这可能是你想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.