Answer the question
In order to leave comments, you need to log in
Logging to different files in Python3?
Hello.
Tell me how to implement logging to different files from different loggers ("left" and "right" logger).
Now this is the code:
log_left = logging.getLogger()
log_left.setLevel(logging.DEBUG)
FH_left = logging.FileHandler("left_file.log")
basic_format_left = logging.Formatter('%(asctime)s : [%(levelname)s] : %(message)s')
FH_left.setFormatter(basic_format_left)
log_left.addHandler(FH_left)
log_left.debug('Это ДЭБАГ на левой части')
log_left.info('Это ИНФО на левой части')
log_left.warning('Это Варнинг на левой части')
log_left.error('Это Эррор на левой части')
log_left.critical('Это критикал на левой части')
log_right = logging.getLogger()
log_right.setLevel(logging.DEBUG)
FH_right = logging.FileHandler("right_file.log")
basic_format_right = logging.Formatter('%(asctime)s : [%(levelname)s] : %(message)s')
FH_right.setFormatter(basic_format_right)
log_right.addHandler(FH_right)
log_right.debug('Это ДЭБАГ на правой части')
log_right.info('Это ИНФО на правой части')
log_right.warning('Это Варнинг на правой части')
log_right.error('Это Эррор на правой части')
log_right.critical('Это критикал на правой части')
Answer the question
In order to leave comments, you need to log in
Add a name for loggers
log_left = logging.getLogger('left')
log_right
= logging.getLogger('right')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question