精细化的pytest日志配置

huangapple go评论56阅读模式
英文:

Fine grained logging configuration for pytest

问题

当运行基于 Pytest 的测试时,我想要为我的自己的代码启用调试日志,但不想为第三方库启用调试日志。例如,如果启用调试日志,boto3 会变得非常嘈杂。根据 文档,只能设置所有记录器的整体日志级别。

是否有已知的解决方案或使用 日志配置文件 的解决方法来精确定义我想要查看的内容?

英文:

When running my Pytest based tests, I want to enable debug logging for my own code, but not for 3rd party libraries. For example boto3 gets very noisy if you enable debug logging. According to the docs it is only possible to set the overall log level for all loggers.

Is there a known solution or workaround to use a logging config file to define exactly what exactly I want to see?

答案1

得分: 1

你可以在 yaml 文件 中为任何特定模块分配日志级别,如下所示:

loggers:
  foo.bar.baz:
    level: INFO

或者:

logging:
  level:
    root: DEBUG
    foo.bar.baz: INFO

通配符也受支持。

英文:

You can assign log level for any specific module in yaml file like this:

loggers:
  foo.bar.baz:
    level: INFO

Or this:

logging:
  level:
    root: DEBUG
    foo.bar.baz: INFO

Wildcards supported too.

huangapple
  • 本文由 发表于 2023年2月27日 19:07:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75579680.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定