小编Rob*_*rtG的帖子

Python 参数中函数的日志记录开销

我正在使用 python 日志记录模块(python 3.4.3)。假设我的日志记录级别设置为 INFO,并且我想使用一个函数作为我的日志记录消息的参数。

现在我期望当日志级别降低(例如警告)时,参数函数不会被执行。

这是真的?

示例(控制台):

>>> import math
>>> import logging
>>> logging.basicConfig(level=logging.INFO)
>>> logging.debug('Factorial of 100000=',math.factorial(100000))
>>> */empty output but slightly delayed, small CPU peak/*
>>> logging.debug('Factorial of 10=',math.factorial(10))
>>> */empty output but instant, no noticeable CPU usage/*
Run Code Online (Sandbox Code Playgroud)

该函数可能没有执行,但仍然存在明显的延迟。有人可以向我解释一下可能的原因吗?

python logging

6
推荐指数
1
解决办法
2311
查看次数

标签 统计

logging ×1

python ×1