Skip to content

Instantly share code, notes, and snippets.

@efr2et
Forked from numberoverzero/_trace.py
Created May 16, 2023 11:11
Show Gist options
  • Save efr2et/cca01f078ad6fd9ca190b351d8a0788a to your computer and use it in GitHub Desktop.
Save efr2et/cca01f078ad6fd9ca190b351d8a0788a 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