python - 日志文件中的 matplotlib.font_manager 调试消息

标签 python logging python-logging

我想在日志文件中记录优化的进度,但我的日志文件被来自 matplotlib 字体管理器的内容填满,例如:

DEBUG:matplotlib.font_manager:findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0.)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'STIXSizeThreeSym' (STIXSizThreeSymBol.ttf) normal normal bold normal>) = 10.335)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'cmmi10' (cmmi10.ttf) normal normal 400 normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'STIXSizeTwoSym' (STIXSizTwoSymReg.ttf) normal normal regular normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'cmsy10' (cmsy10.ttf) normal normal 400 normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans' (DejaVuSans-BoldOblique.ttf) oblique normal bold normal>) = 1.335)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans Mono' (DejaVuSansMono-BoldOblique.ttf) oblique normal bold normal>) = 11.335)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'STIXSizeOneSym' (STIXSizOneSymReg.ttf) normal normal regular normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans Mono' (DejaVuSansMono.ttf) normal normal 400 normal>) = 10.05)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans' (DejaVuSans-Bold.ttf) normal normal bold normal>) = 0.33499999999999996)
DEBUG:matplotlib.font_manager:findfont: score(<Font 'DejaVu Sans Mono' (DejaVuSansMono-Bold.ttf) normal normal bold normal>) = 10.335)

我按如下方式使用记录器:

import logging

logger=logging.getLogger(__name__)

logging.basicConfig(filename='logfile.log',level=logging.DEBUG,
                    format='%(levelname)s:%(name)s:%(message)s)')

def objective(x):

    obj=model(x)
    logger.debug('objective = {}'.format(obj))

    return obj

如何防止 matplotlib 在我的日志文件中乱七八糟?

最佳答案

tomjn提供的解决方案:

basicConfig 中的

level=logging.DEBUG 已删除,位于 logger.setLevel(logging.DEBUG) 下面的行中 加入。这样就使得

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

关于python - 日志文件中的 matplotlib.font_manager 调试消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58320567/

相关文章:

python - 仅当外键存在时才保存内容的标准方法是什么?

python - 创建conda环境: "Found conflicts!" when solving environment and "Finding shortest conflict path" running forever

c# - Windows IoT - 在 C# 中记录事件

Java 登录到 2 个不同的文件

python.logging : Why does my non-basicConfig setting not work?

python - 如何使用 Beautiful soup 和 python 获取团队文本和得分?

python - 带大文件的flask make_response

python - 禁止 Python 日志记录模块中的换行符

python:测试发送日志到系统日志服务器

使用多线程 + 多处理的 Python 日志记录