从 systemD 中的新服务登录到 syslog
Logging into syslog from a new service in systemD
我在 systemD 中创建了一个新服务,到目前为止它没有做任何事情,我只是想一步一步地检查一切是否 运行。
为此,我正在添加日志,但是它没有出现在 Syslog 中,我知道这是服务的默认设置。
当我在我的代码中使用简单打印时,它确实出现在 Syslog 中
import logging
class recoveryService:
def __init__(self):
self.id = 'integ38'
print self.id # prints to log
logging.info("the id is {}".format(self.id)) #does not print to log
def run(self):
print 'reached run' #prints to log
logging.info('reached run log') #does not print to log
if __name__ == '__main__':
recovery = recoveryService()
recovery.run()
如何让这些日志记录出现在系统日志中?
logging.getLogger().setLevel('INFO')
在第一次记录调用之前调用一次。根记录器的默认级别是 WARNING
,因此不显示低于该级别的日志。另请注意,定义处理程序或使用 logging.basicConfig 设置日志记录是一种很好的做法。
我在 systemD 中创建了一个新服务,到目前为止它没有做任何事情,我只是想一步一步地检查一切是否 运行。
为此,我正在添加日志,但是它没有出现在 Syslog 中,我知道这是服务的默认设置。
当我在我的代码中使用简单打印时,它确实出现在 Syslog 中
import logging
class recoveryService:
def __init__(self):
self.id = 'integ38'
print self.id # prints to log
logging.info("the id is {}".format(self.id)) #does not print to log
def run(self):
print 'reached run' #prints to log
logging.info('reached run log') #does not print to log
if __name__ == '__main__':
recovery = recoveryService()
recovery.run()
如何让这些日志记录出现在系统日志中?
logging.getLogger().setLevel('INFO')
在第一次记录调用之前调用一次。根记录器的默认级别是 WARNING
,因此不显示低于该级别的日志。另请注意,定义处理程序或使用 logging.basicConfig 设置日志记录是一种很好的做法。