xolox / python-verboselogs

Verbose logging for Python's logging module
http://verboselogs.readthedocs.io/
MIT License
35 stars 8 forks source link

Rename `spam` level to `trace` #11

Open karolzlot opened 2 years ago

karolzlot commented 2 years ago

I put this idea for considaration.


Trace level is used for example in following libraries:

nLog (C#)

log4j (Java)

rasa commented 1 year ago

@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)

which outputs: ex