【发布时间】:2011-01-14 13:36:37
【问题描述】:
是否有一些相对简单的方法可以以编程方式将源代码行包含到 python 记录器报告中。比如……
import logging
def main():
something_is_not_right = True
logging.basicConfig(level=logging.DEBUG,
format=('%(filename)s: '
'%(levelname)s: '
'%(funcName)s(): '
'%(lineno)d:\t'
'%(message)s')
)
if something_is_not_right == True:
logging.debug('some way to get previous line of source code here?')
所以输出看起来像这样。
example.py: DEBUG: main(): 14: if something_is_not_right == True:
【问题讨论】:
-
不是已经这样做了吗?
-
@marcog 很抱歉我无法更清楚地解释我的问题。 TryPyPy 和 unutbu 理解我在寻找什么。希望他们的回答能解释我的追求。
-
我也做了和marcog一样的假设,不明白问题出在哪里。也许编辑您的问题以阅读“以编程方式包含 arbitrary 源代码行,而不仅仅是记录的行”