<s> """<STR_LIT>""" <EOL> import logging <EOL> import logging . handlers as log_hdlr <EOL> import os <EOL> import sys <EOL> ONEK = <NUM_LIT> <EOL> ONEMEG = ( <NUM_LIT> * <NUM_LIT> ) <EOL> MAX_BYTES = ( <NUM_LIT:5> * ONEMEG ) <EOL> BACKUP_COUNT = <NUM_LIT:10> <EOL> DAYS = '<STR_LIT:D>' <EOL> SECONDS = '<STR_LIT:S>' <EOL> MINUTES = '<STR_LIT:M>' <EOL> HOURS = '<STR_LIT:H>' <EOL> MIDNIGHT = '<STR_LIT>' <EOL> LOG_LEVELS = { '<STR_LIT>' : logging . DEBUG , <EOL> '<STR_LIT:info>' : logging . INFO , <EOL> '<STR_LIT>' : logging . WARNING , <EOL> '<STR_LIT:error>' : logging . ERROR , <EOL> '<STR_LIT>' : logging . CRITICAL } <EOL> _loggers = { } <EOL> def getLogger ( name ) : <EOL> if name in _loggers : <EOL> return _loggers [ name ] <EOL> logger = logging . getLogger ( name ) <EOL> _loggers [ name ] = logger <EOL> return logger <EOL> def setup_logger ( project , cfg ) : <EOL> if _loggers . get ( project ) : <EOL> return <EOL> logger = getLogger ( None ) <EOL> level = LOG_LEVELS . get ( cfg . dfa_log . log_level . lower ( ) , logging . WARNING ) <EOL> logger . setLevel ( level ) <EOL> def_log_levels = cfg . dfa_log . default_log_levels <EOL> for dll in def_log_levels . split ( '<STR_LIT:U+002C>' ) : <EOL> mod , sep , lvl = dll . partition ( '<STR_LIT:=>' ) <EOL> level = LOG_LEVELS . get ( lvl . lower ( ) , logging . WARNING ) <EOL> logging . getLogger ( mod ) . setLevel ( level ) <EOL> log_dir = cfg . dfa_log . log_dir <EOL> log_file = cfg . dfa_log . log_file <EOL> if log_dir and log_file : <EOL> try : <EOL> if not os . path . exists ( log_dir ) : <EOL> os . makedirs ( log_dir ) <EOL> except OSError : <EOL> pass <EOL> else : <EOL> log_file_path = os . path . join ( log_dir , log_file ) <EOL> handler = log_hdlr . TimedRotatingFileHandler ( log_file_path , <EOL> when = DAYS , <EOL> interval = <NUM_LIT:1> ) <EOL> else : <EOL> handler = logging . StreamHandler ( sys . stdout ) <EOL> if cfg . dfa_log . use_syslog . lower ( ) == '<STR_LIT:true>' : <EOL> log_fac = cfg . dfa_log . syslog_log_facility <EOL> facility = getattr ( log_hdlr . SysLogHandler , log_fac , None ) <EOL> handler = log_hdlr . SysLogHandler ( address = '<STR_LIT>' , <EOL> facility = facility ) <EOL> log_format = cfg . dfa_log . log_format <EOL> date_fowrmat = cfg . dfa_log . log_date_format <EOL> formatter = logging . Formatter ( fmt = log_format , datefmt = date_fowrmat ) <EOL> handler . setFormatter ( formatter ) <EOL> logger . addHandler ( handler ) <EOL> _loggers [ project ] = logger </s>
