Skip to content

Instantly share code, notes, and snippets.

@numberoverzero
Created August 3, 2017 16:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save numberoverzero/f803ebf29a0677b6980a5a733a10ca71 to your computer and use it in GitHub Desktop.
Save numberoverzero/f803ebf29a0677b6980a5a733a10ca71 to your computer and use it in GitHub Desktop.
add TRACE level to python logging
import logging
_trace_installed = False
def install_trace_logger():
global _trace_installed
if _trace_installed:
return
level = logging.TRACE = logging.DEBUG - 5
def log_logger(self, message, *args, **kwargs):
if self.isEnabledFor(level):
self._log(level, message, args, **kwargs)
logging.getLoggerClass().trace = log_logger
def log_root(msg, *args, **kwargs):
logging.log(level, msg, *args, **kwargs)
logging.addLevelName(level, "TRACE")
logging.trace = log_root
_trace_installed = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment