logger file

This commit is contained in:
Divided by Zer0 2022-09-11 22:59:19 +02:00
parent 432af79fa5
commit ce2d1ff654
2 changed files with 30 additions and 1 deletions

View File

@ -17,8 +17,14 @@ os.environ['TOKENIZERS_PARALLELISM'] = 'false'
from eventlet import tpool
import logging
from loguru import logger
from logger import logger
logger.generation("This is a generation message")
logger.debug("That's it, beautiful and simple logging!")
logger.info("That's it, beautiful and simple logging!")
logger.error("That's it, beautiful and simple logging!")
logger.critical("That's it, beautiful and simple logging!")
logging.getLogger("urllib3").setLevel(logging.ERROR)
from os import path, getcwd

23
logger.py Normal file
View File

@ -0,0 +1,23 @@
import sys
from functools import partialmethod
from loguru import logger
def is_stdout_log(record):
if record["level"].name == "GENERATION":
return(True)
return(False)
def is_stderr_log(record):
if record["level"].name != "GENERATION":
return(True)
return(False)
logfmt = "<level>{level: <10}</level> | <green>{name}</green>:<green>{function}</green>:<green>{line}</green> - <level>{message}</level>"
genfmt = "<level>{level: <10}</level> @ <green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{message}</level>"
new_level = logger.level("GENERATION", no=21, color="<cyan>")
logger.__class__.generation = partialmethod(logger.__class__.log, "GENERATION")
config = {
"handlers": [
{"sink": sys.stderr, "format": logfmt, "colorize":True, "filter": is_stderr_log},
{"sink": sys.stdout, "format": genfmt, "level": "GENERATION", "colorize":True, "filter": is_stdout_log},
],
}
logger.configure(**config)