Python logging - Is there something below DEBUG?

The answer from @voitek works great, but he forgot to monkey patch logging.verbose.

logging.VERBOSE = 5
logging.addLevelName(logging.VERBOSE, "VERBOSE")
logging.Logger.verbose = lambda inst, msg, *args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs)
logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg, *args, **kwargs)

This will now also work with;

logging.verbose(*args, **kwargs)

You can even go further and add a logger.verbose method, although I strongly suggest you don't for various reasons (pretty much covered in logging's how-to). Anyway, if you decide that you really want to have one, here's the code:

logging.VERBOSE = 5
logging.addLevelName(logging.VERBOSE, "VERBOSE")
logging.Logger.verbose = lambda inst, msg, *args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs)

DEBUG is the lowest level out of the ones provided by the logging module: ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'). Their numeric values are here: http://docs.python.org/howto/logging.html#logging-levels

You can create custom levels (though the docs say that that should rarely be necessary and may even be undesirable). If you want to add a level, the technique is simple:

>>> logging.addLevelName(5, "VERBOSE")

Eventhough you can add a custom level, it may be a better approach to add some filters that provide a finer level of control.

Tags:

Python

Logging