views:

96

answers:

2

If I set the logging module to DEBUG with a command line parameter like this:

if (opt["log"] == "debug"):
  logging.basicConfig(level=logging.DEBUG)

How can I later tell if the logger was set to DEBUG? I'm writing a decorator that will time a function if True flag is passed to it, and if no flag is given, it defaults to printing timing information when the root logger is set to DEBUG.

+4  A: 
logging.getLogger().getEffectiveLevel()

logging.getLogger() without arguments gets the root level logger.

http://docs.python.org/library/logging.html#logging.Logger.getEffectiveLevel

Tor Valamo
Excellent, thanks! I was doing something like that (except passing explicit "root" to getLogger), but I was doing it in the __init__ function of my decorator, before the logger was set to debug :\
gct