-
-
Save efr2et/cca01f078ad6fd9ca190b351d8a0788a to your computer and use it in GitHub Desktop.
add TRACE level to python logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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