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

0 投票
1 回答
1493 浏览
提问于 2025-04-17 04:00

从一个导入的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

你可以很简单地创建一个自定义的日志处理器,并把它分配给你模块使用的日志记录器。

详细信息可以查看 这里

撰写回答