Rename `spam` level to `trace`
karolzlot opened this issue · comments
@karolzlot I use colorlogs with haggis to easily add a TRACE level, which coloredlogs respects as it uses the same loglevel as SPAM (5):
#!/usr/bin/env python3
# pylint: disable=E1101
"""ex"""
import logging
import coloredlogs # type: ignore
import haggis.logs # type: ignore
haggis.logs.add_logging_level("TRACE", logging.DEBUG - 5)
level_styles = coloredlogs.DEFAULT_LEVEL_STYLES
level_styles["trace"] = dict(color="cyan")
coloredlogs.install(level=logging.TRACE, level_styles=level_styles) # type: ignore
logging.trace("trace (%d)", logging.getLevelName("TRACE")) # type: ignore
logging.debug("debug (%d)", logging.getLevelName("DEBUG"))
logging.info("info (%d)", logging.getLevelName("INFO"))
logging.warning("warning (%d)", logging.getLevelName("WARNING"))
logging.error("error (%d)", logging.getLevelName("ERROR"))
logging.critical("critical (%d)", logging.getLevelName("CRITICAL"))
try:
raise UserWarning("exception message")
except UserWarning as exc:
logging.exception(exc)