<s> import sys <EOL> import logging <EOL> import traceback <EOL> def loglevel_from_str ( log_level_str ) : <EOL> log_level_str = log_level_str . upper ( ) <EOL> numeric_level = getattr ( logging , log_level_str , None ) <EOL> if not isinstance ( numeric_level , int ) : <EOL> raise ValueError ( '<STR_LIT>' % log_level_str ) <EOL> return numeric_level <EOL> def setup_loggers ( config ) : <EOL> activity_log_file = config [ '<STR_LIT>' ] <EOL> errors_log_file = config [ '<STR_LIT>' ] <EOL> log_level = loglevel_from_str ( config [ '<STR_LIT>' ] ) <EOL> log_format = "<STR_LIT>" <EOL> formatter = logging . Formatter ( log_format ) <EOL> stdout_stream = logging . StreamHandler ( sys . stdout ) <EOL> stdout_stream . setFormatter ( formatter ) <EOL> activity_file_stream = logging . FileHandler ( activity_log_file ) <EOL> activity_file_stream . setFormatter ( formatter ) <EOL> errors_file_stream = logging . FileHandler ( errors_log_file ) <EOL> errors_file_stream . setFormatter ( formatter ) <EOL> activity_logger = logging . getLogger ( "<STR_LIT>" ) <EOL> activity_logger . setLevel ( log_level ) <EOL> activity_logger . addHandler ( activity_file_stream ) <EOL> activity_logger . addHandler ( stdout_stream ) <EOL> errors_logger = logging . getLogger ( "<STR_LIT>" ) <EOL> errors_logger . setLevel ( logging . WARNING ) <EOL> errors_logger . addHandler ( errors_file_stream ) <EOL> return activity_logger , errors_logger <EOL> def log_critical ( e ) : <EOL> errors_logger = logging . getLogger ( "<STR_LIT>" ) <EOL> tb = traceback . format_exc ( ) <EOL> errors_logger . critical ( '<STR_LIT>' . join ( tb ) ) <EOL> errors_logger . critical ( '<STR_LIT>' . format ( type ( e ) , e . message ) ) <EOL> logging . critical ( '<STR_LIT>' . join ( tb ) ) <EOL> logging . critical ( '<STR_LIT>' . format ( type ( e ) , e . message ) ) </s>
