Reputation: 938
I am trying to capture logs that are created during the course of my python unittests and saw the code here: https://stackoverflow.com/a/1049375/576333.
However, I cannot get this code to work and will freely admit that my understanding of python's logging module is not fantastic.
Essentially, I am adding the mock handler in that post like so: my_logger.addHandler(MockLoggingHandler)
and when the code calls, say, my_logger.info(some_message)
I get
AttributeError: class MockLoggingHandler has no attribute 'level'
I am not sure where to start on figuring out what is missing from the MockLoggingHandler
class. BTW, I am using Python 2.6.8.
Upvotes: 4
Views: 2407
Reputation: 99530
You need to add an instance of the class, like so:
my_logger.addHandler(MockLoggingHandler())
Note the ()
after MockLoggingHandler
.
Upvotes: 6