This commit is contained in:
parent
183755e637
commit
b59a8ef323
|
@ -1,32 +1,34 @@
|
|||
import logging
|
||||
import colorlog
|
||||
|
||||
def get_colorful_logger(name='root'):
|
||||
# Define the color scheme
|
||||
color_scheme = {
|
||||
'DEBUG': 'light_black',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white',
|
||||
}
|
||||
|
||||
# Define secondary log colors
|
||||
secondary_colors = {
|
||||
'log_name': {'DEBUG': 'blue'},
|
||||
'asctime': {'DEBUG': 'cyan'},
|
||||
'process': {'DEBUG': 'purple'},
|
||||
'module': {'DEBUG': 'light_black,bg_blue'},
|
||||
}
|
||||
# Define the color scheme
|
||||
color_scheme = {
|
||||
'DEBUG': 'light_black',
|
||||
'INFO': 'green',
|
||||
'WARNING': 'yellow',
|
||||
'ERROR': 'red',
|
||||
'CRITICAL': 'red,bg_white',
|
||||
}
|
||||
|
||||
# Create a ColoredFormatter object for colorized logging
|
||||
formatter = colorlog.ColoredFormatter(
|
||||
"%(log_color)s%(levelname)s: %(log_color)s[%(module)s]%(reset)s %(white)s%(message)s",
|
||||
log_colors=color_scheme,
|
||||
secondary_log_colors=secondary_colors, # Set secondary log colors
|
||||
style='%',
|
||||
reset=True
|
||||
)
|
||||
# Define secondary log colors
|
||||
secondary_colors = {
|
||||
'log_name': {'DEBUG': 'blue'},
|
||||
'asctime': {'DEBUG': 'cyan'},
|
||||
'process': {'DEBUG': 'purple'},
|
||||
'module': {'DEBUG': 'light_black,bg_blue'},
|
||||
}
|
||||
|
||||
# Create a ColoredFormatter object for colorized logging
|
||||
formatter = colorlog.ColoredFormatter(
|
||||
"%(log_color)s%(levelname)s: %(log_color)s[%(module)s]%(reset)s %(white)s%(message)s",
|
||||
log_colors=color_scheme,
|
||||
secondary_log_colors=secondary_colors, # Set secondary log colors
|
||||
style='%',
|
||||
reset=True
|
||||
)
|
||||
|
||||
def get_colorful_logger(name='main'):
|
||||
|
||||
# Create a stream handler for logging output
|
||||
stream = logging.StreamHandler()
|
||||
|
@ -39,4 +41,8 @@ def get_colorful_logger(name='root'):
|
|||
|
||||
return logger
|
||||
|
||||
root_logger = get_colorful_logger()
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(logging.DEBUG) # Set the log level
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(formatter)
|
||||
root_logger.addHandler(stream_handler)
|
||||
|
|
Loading…
Reference in New Issue
Block a user