gpt4 book ai didi

python 记录 : is it possible to add module name to formatter

转载 作者:太空狗 更新时间:2023-10-30 02:20:05 24 4
gpt4 key购买 nike

可以通过模块名称获取记录器。像这样:

logging.getLogger(module_name)

我想将 module_name 添加到每条日志记录中。是否可以设置一个添加 module_nameFormatter 对象?

最佳答案

您正在寻找%(name)s 参数;将其添加到您的格式化程序模式中:

FORMAT = "%(name)s: %(message)s"
logging.basicConfig(format=FORMAT)

或者在创建 Formatter() 时:

FORMAT = "%(name)s: %(message)s"
formatter = logging.Formatter(fmt=FORMAT)

参见 LogRecord attributes reference :

Attribute name: name
Format: %(name)s
Description: Name of the logger used to log the call.

关于 python 记录 : is it possible to add module name to formatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com