4

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.

1 Answer 1

6

You need to add an instance of the class, like so:

my_logger.addHandler(MockLoggingHandler())

Note the () after MockLoggingHandler.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.