<s> '''<STR_LIT>''' <EOL> from logging . handlers import TimedRotatingFileHandler <EOL> from threading import Thread <EOL> import logging <EOL> """<STR_LIT>""" <EOL> class QueueHandler ( logging . Handler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , queue , logger_name ) : <EOL> logging . Handler . __init__ ( self ) <EOL> self . queue = queue <EOL> self . logger_name = logger_name <EOL> def enqueue ( self , record ) : <EOL> self . queue . put_nowait ( record ) <EOL> def prepare ( self , record ) : <EOL> self . format ( record ) <EOL> record . msg = record . message <EOL> record . logger_name = self . logger_name <EOL> record . args = None <EOL> record . exc_info = None <EOL> return record <EOL> def emit ( self , record ) : <EOL> try : <EOL> self . enqueue ( self . prepare ( record ) ) <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> raise <EOL> except : <EOL> self . handleError ( record ) <EOL> class LogCollector ( Thread ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , log_queue ) : <EOL> Thread . __init__ ( self ) <EOL> self . log_queue = log_queue <EOL> self . daemon = True <EOL> def run ( self ) : <EOL> while True : <EOL> try : <EOL> record = self . log_queue . get ( ) <EOL> logger = logging . getLogger ( record . logger_name ) <EOL> logger . handle ( record ) <EOL> except : <EOL> pass <EOL> def create_multiprocess_logger ( logger_name , persist_logger_name , log_level , log_format , log_queue , log_file_path , <EOL> when_to_rotate , keep_log_days ) : <EOL> """<STR_LIT>""" <EOL> queue_log_formatter = logging . Formatter ( log_format ) <EOL> queue_log_handler = QueueHandler ( log_queue , persist_logger_name ) <EOL> queue_log_handler . setFormatter ( queue_log_formatter ) <EOL> queue_logger = logging . getLogger ( logger_name ) <EOL> queue_logger . setLevel ( log_level ) <EOL> queue_logger . handlers = [ ] <EOL> queue_logger . addHandler ( queue_log_handler ) <EOL> queue_logger . propagate = False <EOL> persist_log_formatter = logging . Formatter ( '<STR_LIT>' ) <EOL> persist_log_handler = TimedRotatingFileHandler ( log_file_path , when = when_to_rotate , interval = <NUM_LIT:1> , backupCount = keep_log_days ) <EOL> persist_log_handler . setFormatter ( queue_log_formatter ) <EOL> persist_logger = logging . getLogger ( persist_logger_name ) <EOL> persist_logger . setLevel ( log_level ) <EOL> persist_logger . handlers = [ ] <EOL> persist_logger . addHandler ( persist_log_handler ) <EOL> persist_logger . propagate = False </s>
