我遵循了 Django 文档的建议,像这样使用日志记录:
I followed the advice of the django docs, and use logging like this:
import logging
logger = logging.getLogger(__name__)
def today(...):
logger.info('Sun is shining, the weather is sweet')
使用当前的配置,输出结果如下:
2016-08-11 14:54:06 mylib.foo.today: INFO Sun is shining, the weather is sweet
不幸的是,一些我无法修改的库使用这种方式进行日志记录:
import logging
def third_party(...):
logging.info('Make you want to move your dancing feet')
输出结果很遗憾,看起来像这样:
2016-08-09 08:28:04 root.third_party: INFO Make you want to move your dancing feet
我想看看这个:
2016-08-09 08:28:04 other_lib.some_file.third_party: INFO Make you want to move your dancing feet
区别:
root.third_party ==> other_lib.some_file.third_party
如果代码使用logging.info()
而不是logger.info()
,我想看到长版本(不是root
)
更新
这不是Elegant setup of Python logging in Django的重复,因为它的解决方案是:
引用开始
在每个模块中,我使用以下内容定义记录器
logger = logging.getLogger(__name__)
引用结束。
不,我不会修改使用logging.info()
而不是logger.info()
的第三方代码。
跟进问题
logger = logging.getLogger(__name__)
的记录器。 - guettli