[英]Python syslog - view syslog messages
I'm running the following code: # create logger logger = logging.getLogger("myApp") logger.setLevel(logging.DEBUG) 我正在运行以下代码:#创建logger logger = logging.getLogger(“ myApp”)logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# add ch to logger
logger.addHandler(ch)
logger.debug('debug sample message')
Now, on a different python script, I'd like to read those messages (that belongs to "myApp", from syslog) - how can I do so??? 现在,在另一个python脚本上,我想读取这些消息(属于syslog的“ myApp”)-我该怎么做?
Thanks a lot, Efrat 非常感谢,Efrat
you can read as file : 您可以阅读为文件:
important = []
keep_phrases = ["test",
"important",
"warning"]
with open("log.log" 'r') as f:
for line in f:
for phrase in keep_phrases:
if phrase in line:
important.append(line)
print line
break
print(important)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.