本文介绍了如何通过Python登录到日志记录(systemd)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望logging.info()
去记录日志(systemd).
I would like logging.info()
to go to journald (systemd).
到目前为止,我只找到了读取日志记录的python模块(不是我想要的)或像这样工作的模块:journal.send('Hello world')
Up to now I only found python modules which read journald (not what I want) or modules which work like this: journal.send('Hello world')
推荐答案
python-systemd 具有 JournalHandler 可以与日志记录框架一起使用.
python-systemd has a JournalHandler you can use with the logging framework.
从文档中:
import logging
from systemd.journal import JournalHandler
log = logging.getLogger('demo')
log.addHandler(JournalHandler())
log.setLevel(logging.INFO)
log.info("sent to journal")
这篇关于如何通过Python登录到日志记录(systemd)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!