Add TRACE log level

This is useful for when we want important debug messages, but not
necessarily to be flooded with every message that comes through IRC

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2024-07-18 11:02:02 -07:00
parent f700c0f34c
commit 40a859083a
2 changed files with 15 additions and 1 deletions

View File

@@ -8,6 +8,20 @@ import sys
from .config import ServerConfig from .config import ServerConfig
from .bot import Bot from .bot import Bot
# ADD TRACE
# add TRACE logging level to logging module
TRACE = 5
logging.addLevelName(TRACE, "TRACE")
logging.TRACE = TRACE
def trace(self, message, *args, **kwargs):
if self.isEnabledFor(TRACE):
#args = list(map(str, args))
self._log(TRACE, message, args, **kwargs)
logging.Logger.trace = trace
# END ADD TRACE
parser = argparse.ArgumentParser(description="Run an IRC bot") parser = argparse.ArgumentParser(description="Run an IRC bot")
parser.add_argument("-c", "--config", type=str, default=None) parser.add_argument("-c", "--config", type=str, default=None)
parser.add_argument( parser.add_argument(

View File

@@ -82,7 +82,7 @@ class ServerConfig:
if "loglevel" in obj: if "loglevel" in obj:
if not isinstance(obj["loglevel"], str): if not isinstance(obj["loglevel"], str):
raise ConfigError("loglevel", "must be a string") raise ConfigError("loglevel", "must be a string")
loglevels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] loglevels = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
if obj["loglevel"] not in loglevels: if obj["loglevel"] not in loglevels:
raise ConfigError("loglevel", "must be one of: " + " ".join(loglevels)) raise ConfigError("loglevel", "must be one of: " + " ".join(loglevels))
self.loglevel = obj["loglevel"] self.loglevel = obj["loglevel"]