如何使记录器全局化,以便我可以在每个模块中使用它?Python全局日志记录
像这样的东西在moduleA:
import logging
import moduleB
log = logging.getLogger('')
result = moduleB.goFigure(5)
log.info('Answer was', result)
有了这个moduleB:
def goFigure(integer):
if not isinstance(integer, int):
log.critical('not an integer')
else:
return integer + 1
目前,我会得到一个错误,因为moduleB不知道什么log
是。我该如何解决这个问题?
非常感谢你 – MFB
即使使用自定义记录器设置,该解决方案也能像魅力一样工作。 – Centurion