相关疑难解决方法(0)

Python全局日志记录

如何使Logger全局化,以便我可以在我制作的每个模块中使用它?

在moduleA中有类似的东西:

import logging
import moduleB

log = logging.getLogger('')

result = moduleB.goFigure(5)
log.info('Answer was', result)
Run Code Online (Sandbox Code Playgroud)

在moduleB中有了这个:

def goFigure(integer):
    if not isinstance(integer, int):
        log.critical('not an integer')
    else:
        return integer + 1
Run Code Online (Sandbox Code Playgroud)

目前,我会收到错误,因为moduleB不知道是什么log.我该如何解决这个问题?

python logging

7
推荐指数
2
解决办法
9836
查看次数

标签 统计

logging ×1

python ×1