系统日志中的多行日志记录
所以我已经配置我的Python应用程序使用Python的SysLogHandler登录到syslog,一切正常。除了多线处理。并不是说我需要如此糟糕地发出多行日志记录(我做了一点),但我需要能够阅读Python的异常。我正在使用Ubuntu和rsyslog 4.2.0。这就是我得到的:
Mar 28 20:11:59 telemachos root: ERROR 'EXCEPTION'#012Traceback (most recent call last):#012 File "./test.py", line 22, in <module>#012 foo()#012 File "./test.py", line 13, in foo#012 bar()#012 File "./test.py", line 16, in bar#012 bla()#012 File "./test.py", line 19, in bla#012 raise Exception("EXCEPTION!")#012Exception: EXCEPTION!
测试代码,以备不时之需:
import logging
from logging.handlers import SysLogHandler
logger = logging.getLogger()
logger.setLevel(logging.INFO)
syslog = SysLogHandler(address='/dev/log', facility='local0')
formatter = logging.Formatter('%(name)s: %(levelname)s %(message)r')
syslog.setFormatter(formatter)
logger.addHandler(syslog)
def foo():
bar()
def bar():
bla()
def bla():
raise Exception("EXCEPTION!")
try:
foo()
except:
logger.exception("EXCEPTION")
没有找到相关结果
已邀请:
3 个回复
疾很毋悲
泪琉踞檄
肺鬼耙扮群
- 然后你可以为你发送的文本中的每一行调用超类
。就像是: