Skip to content

Commit

Permalink
Move facedancer logging to a sub-logger of the python root
Browse files Browse the repository at this point in the history
Issue originally reported in #51
Initial pull-request in #52

Closes #51
Closes #52
  • Loading branch information
antoinevg committed Jan 23, 2024
1 parent e0b2b8e commit 131d96b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions facedancer/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import functools
import logging
import sys


LOGLEVEL_TRACE = logging.DEBUG + 2

LOG_FORMAT_COLOR = "\u001b[37;1m%(levelname)-8s| \u001b[0m\u001b[1m%(module)-15s|\u001b[0m %(message)s"
LOG_FORMAT_PLAIN = "%(levelname)-8s| %(module)-15s| %(message)s"


def configure_default_logging(level=logging.INFO, logger=logging):
if sys.stdout.isatty():
log_format = LOG_FORMAT_COLOR
else:
log_format = LOG_FORMAT_PLAIN

logger.basicConfig(level=level, format=log_format)
logging.getLogger("facedancer").level = level


def _initialize_logging():
# add a TRACE level to logging
logging.TRACE = LOGLEVEL_TRACE
logging.addLevelName(logging.TRACE, "TRACE")
logging.Logger.trace = functools.partialmethod(logging.Logger.log, logging.TRACE)
logging.trace = functools.partial(logging.log, logging.TRACE)

# Configure facedancer logger
logger = logging.getLogger("facedancer")
logger.level = logging.WARN

return logger


log = _initialize_logging()

0 comments on commit 131d96b

Please sign in to comment.