bunkerweb/utils/logger.py
2022-10-19 17:37:13 +02:00

38 lines
921 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="[%Y-%m-%d %H:%M:%S]",
level=logging.INFO,
)
# Edit the default levels of the logging module
logging.addLevelName(logging.CRITICAL, "🚨")
logging.addLevelName(logging.DEBUG, "🐛")
logging.addLevelName(logging.ERROR, "")
logging.addLevelName(logging.INFO, " ")
logging.addLevelName(logging.WARNING, "⚠️ ")
def setup_logger(title: str, level=logging.INFO) -> logging.Logger:
"""Set up local logger"""
title = title.upper()
logger = logging.getLogger(title)
if level not in (
logging.DEBUG,
logging.INFO,
logging.WARNING,
logging.ERROR,
logging.CRITICAL,
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL",
):
level = logging.INFO
logger.setLevel(level)
return logger