fear: formatted logger
This commit is contained in:
parent
b3ac152220
commit
2c504d3123
@ -11,13 +11,39 @@ if True:
|
|||||||
import sys
|
import sys
|
||||||
sys.setrecursionlimit(100)
|
sys.setrecursionlimit(100)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomFormatter(logging.Formatter):
|
||||||
|
grey = "\x1b[38;20m"
|
||||||
|
yellow = "\x1b[33;20m"
|
||||||
|
red = "\x1b[31;20m"
|
||||||
|
bold_red = "\x1b[31;1m"
|
||||||
|
reset = "\x1b[0m"
|
||||||
|
format = logging_settings['logging_format']
|
||||||
|
|
||||||
|
FORMATS = {
|
||||||
|
logging.DEBUG: grey + format + reset,
|
||||||
|
logging.INFO: grey + format + reset,
|
||||||
|
logging.WARNING: yellow + format + reset,
|
||||||
|
logging.ERROR: red + format + reset,
|
||||||
|
logging.CRITICAL: bold_red + format + reset
|
||||||
|
}
|
||||||
|
|
||||||
|
def format(self, record):
|
||||||
|
log_fmt = self.FORMATS.get(record.levelno)
|
||||||
|
formatter = logging.Formatter(log_fmt)
|
||||||
|
return formatter.format(record)
|
||||||
|
|
||||||
|
|
||||||
|
stream_handler = logging.StreamHandler()
|
||||||
|
stream_handler.setFormatter(CustomFormatter())
|
||||||
|
|
||||||
# configure logger default
|
# configure logger default
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging_settings['log_level'] if not DEBUG_LOGGIN else logging.DEBUG,
|
level=logging_settings['log_level'] if not DEBUG_LOGGIN else logging.DEBUG,
|
||||||
format=logging_settings['logging_format'],
|
format=logging_settings['logging_format'],
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.FileHandler(main_settings['log_file']),
|
logging.FileHandler(main_settings['log_file']),
|
||||||
logging.StreamHandler()
|
stream_handler
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,3 +12,8 @@ class BColors:
|
|||||||
ENDC = "\033[0m"
|
ENDC = "\033[0m"
|
||||||
BOLD = "\033[1m"
|
BOLD = "\033[1m"
|
||||||
UNDERLINE = "\033[4m"
|
UNDERLINE = "\033[4m"
|
||||||
|
|
||||||
|
GREY = "\x1b[38;20m"
|
||||||
|
YELLOW = "\x1b[33;20m"
|
||||||
|
RED = "\x1b[31;20m"
|
||||||
|
BOLD_RED = "\x1b[31;1m"
|
||||||
|
Loading…
Reference in New Issue
Block a user