<s> """<STR_LIT>""" <EOL> import logging <EOL> import logging . handlers <EOL> import os <EOL> import os . path <EOL> import sys <EOL> from compass . utils import flags <EOL> from compass . utils import setting_wrapper as setting <EOL> flags . add ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , default = setting . DEFAULT_LOGLEVEL ) <EOL> flags . add ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , default = setting . DEFAULT_LOGDIR ) <EOL> flags . add ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , default = None ) <EOL> flags . add ( '<STR_LIT>' , type = '<STR_LIT:int>' , <EOL> help = '<STR_LIT>' , default = setting . DEFAULT_LOGINTERVAL ) <EOL> flags . add ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , default = setting . DEFAULT_LOGINTERVAL_UNIT ) <EOL> flags . add ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' , default = setting . DEFAULT_LOGFORMAT ) <EOL> flags . add ( '<STR_LIT>' , type = '<STR_LIT:int>' , <EOL> help = '<STR_LIT>' , default = setting . DEFAULT_LOGBACKUPCOUNT ) <EOL> LOGLEVEL_MAPPING = { <EOL> '<STR_LIT>' : logging . DEBUG - <NUM_LIT:2> , <EOL> '<STR_LIT>' : logging . DEBUG - <NUM_LIT:1> , <EOL> '<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> } <EOL> logging . addLevelName ( LOGLEVEL_MAPPING [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> logging . addLevelName ( LOGLEVEL_MAPPING [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> logging . getLogger ( ) . setLevel ( logging . CRITICAL ) <EOL> def getLevelByName ( level_name ) : <EOL> """<STR_LIT>""" <EOL> return LOGLEVEL_MAPPING [ level_name ] <EOL> def init ( ) : <EOL> """<STR_LIT>""" <EOL> loglevel = flags . OPTIONS . loglevel . lower ( ) <EOL> logdir = flags . OPTIONS . logdir <EOL> logfile = flags . OPTIONS . logfile <EOL> logger = logging . getLogger ( ) <EOL> if logger . handlers : <EOL> for handler in logger . handlers : <EOL> logger . removeHandler ( handler ) <EOL> if logdir : <EOL> if not logfile : <EOL> logfile = '<STR_LIT>' % os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> handler = logging . handlers . TimedRotatingFileHandler ( <EOL> os . path . join ( logdir , logfile ) , <EOL> when = flags . OPTIONS . log_interval_unit , <EOL> interval = flags . OPTIONS . log_interval , <EOL> backupCount = flags . OPTIONS . log_backup_count ) <EOL> else : <EOL> if not logfile : <EOL> handler = logging . StreamHandler ( sys . stderr ) <EOL> else : <EOL> handler = logging . handlers . TimedRotatingFileHandler ( <EOL> logfile , <EOL> when = flags . OPTIONS . log_interval_unit , <EOL> interval = flags . OPTIONS . log_interval , <EOL> backupCount = flags . OPTIONS . log_backup_count ) <EOL> if loglevel in LOGLEVEL_MAPPING : <EOL> logger . setLevel ( LOGLEVEL_MAPPING [ loglevel ] ) <EOL> handler . setLevel ( LOGLEVEL_MAPPING [ loglevel ] ) <EOL> formatter = logging . Formatter ( <EOL> flags . OPTIONS . log_format ) <EOL> handler . setFormatter ( formatter ) <EOL> logger . addHandler ( handler ) </s>
