import sys from functools import partialmethod from loguru import logger STDOUT_LEVELS = ["GENERATION", "PROMPT"] def is_stdout_log(record): if record["level"].name in STDOUT_LEVELS: return(True) return(False) def is_stderr_log(record): if record["level"].name not in STDOUT_LEVELS: return(True) return(False) logfmt = "{level: <10} | {name}:{function}:{line} - {message}" genfmt = "{level: <10} @ {time:YYYY-MM-DD HH:mm:ss} | {message}" promptfmt = "{level: <10} @ {time:YYYY-MM-DD HH:mm:ss} | {message}" new_level = logger.level("GENERATION", no=22, color="") new_level = logger.level("PROMPT", no=21, color="") logger.__class__.generation = partialmethod(logger.__class__.log, "GENERATION") logger.__class__.prompt = partialmethod(logger.__class__.log, "PROMPT") config = { "handlers": [ {"sink": sys.stderr, "format": logfmt, "colorize":True, "filter": is_stderr_log}, {"sink": sys.stdout, "format": genfmt, "level": "PROMPT", "colorize":True, "filter": is_stdout_log}, ], } logger.configure(**config)