从导入的python文件中捕获日志消息

时间:2011-10-10 08:01:41

标签: python logging

从导入的python文件中获取日志记录信息。

我正在构建一个基于python的测试套件。 使用__import函数调用测试 我想在我的测试应用程序中捕获日志消息(在测试中)。使用python日志记录模块生成日志消息。 我怎样才能做到这一点 ?例如,在伪代码中:

    for test in testList:  

               # do something
             # Import Test   

             testid = __import__(test)  

             testOut = testid.run(parameter1,parameter2)    

             print "   => Result: %s\n" % testOut            
             # capture logging information from test which imports logging and append to wxpython window

1 个答案:

答案 0 :(得分:0)

您可以轻松创建自定义日志记录处理程序并将其分配给模块使用的记录器。

请参阅http://docs.python.org/library/logging.html#handler-objects

相关问题