0

One of my logger.debug() statements takes input that's fairly labour-intensive.

I know that I should do logger.debug("The spam is %s", spam_temperature) rather than logger.debug("The spam is {}".format(spam_temperature)). The problem is that the operations I need to perform to actually find out the spam_temperature are quite CPU-intensive, and I have no use for them if the logging level is, say, INFO.

What is the best practice in a case like this?

1 Answer 1

0

Found the answer myself - I added python if not logging.getLogger().isEnabledFor(logging.DEBUG): return before the section I wanted to avoid.

(I got the inspiration from https://stackoverflow.com/a/27849836/3061818)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.