运行以下代码时:
import logging
from logging import LoggerAdapter
logging.basicConfig(level=logging.DEBUG)
def f():
logger = logging.getLogger(__name__)
adapter = LoggerAdapter(logger=logger, extra={"client_id": "132"})
adapter.info("test")
if __name__=="__main__":
f()
得到以下输出:
INFO:__main__:test
因此不记录额外的字典。我做错了什么?
添加额外的参数格式化程序。
FORMAT = "%(levelname)s:%(name)s:%(message)s:{"client_id": %(client_id)s}"
logging.basicConfig(level=logging.DEBUG, format=FORMAT)