<s> import syslog <EOL> import os <EOL> import sys <EOL> import logging <EOL> import logging . handlers <EOL> class Logger : <EOL> def __init__ ( self , app_name , log_file , log_level ) : <EOL> self . m_app_name = app_name <EOL> self . m_log_file = log_file <EOL> self . m_log_level = log_level <EOL> self . m_logger = logging . getLogger ( ) <EOL> try : <EOL> handler = logging . handlers . SysLogHandler ( address = log_file ) <EOL> except Exception , ex : <EOL> print "<STR_LIT>" + log_file + "<STR_LIT>" + str ( ex ) + "<STR_LIT>" <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> return <EOL> formatter = logging . Formatter ( '<STR_LIT>' ) <EOL> handler . setFormatter ( formatter ) <EOL> self . m_logger . setLevel ( self . m_log_level ) <EOL> self . m_logger . addHandler ( handler ) <EOL> self . m_HEADER = '<STR_LIT>' <EOL> self . m_OKBLUE = '<STR_LIT>' <EOL> self . m_OKGREEN = '<STR_LIT>' <EOL> self . m_WARNING = '<STR_LIT>' <EOL> self . m_FAIL = '<STR_LIT>' <EOL> self . m_ENDC = '<STR_LIT>' <EOL> def header ( self , string_to_log ) : <EOL> print self . m_HEADER + string_to_log + self . m_ENDC <EOL> return None <EOL> def blue ( self , string_to_log ) : <EOL> print self . m_OKBLUE + string_to_log + self . m_ENDC <EOL> return None <EOL> def green ( self , string_to_log ) : <EOL> print self . m_OKGREEN + string_to_log + self . m_ENDC <EOL> return None <EOL> def warning ( self , string_to_log ) : <EOL> print self . m_WARNING + string_to_log + self . m_ENDC <EOL> return None <EOL> def fail ( self , string_to_log ) : <EOL> print self . m_FAIL + string_to_log + self . m_ENDC <EOL> return None <EOL> def debug ( self , string_to_log ) : <EOL> self . m_logger . debug ( string_to_log ) <EOL> def error ( self , string_to_log ) : <EOL> self . m_logger . error ( string_to_log ) <EOL> def info ( self , string_to_log ) : <EOL> self . m_logger . info ( string_to_log ) <EOL> def warn ( self , string_to_log ) : <EOL> self . m_logger . warn ( string_to_log ) <EOL> def crit ( self , string_to_log ) : <EOL> self . m_logger . critical ( string_to_log ) <EOL> def log ( self , string_to_log , level = <NUM_LIT:6> ) : <EOL> if level == <NUM_LIT:6> : <EOL> self . m_logger . info ( string_to_log ) <EOL> elif level <= <NUM_LIT:2> : <EOL> self . m_logger . critical ( string_to_log ) <EOL> elif level == <NUM_LIT:3> : <EOL> self . m_logger . error ( string_to_log ) <EOL> elif level == <NUM_LIT:4> : <EOL> self . m_logger . warning ( string_to_log ) <EOL> elif level == <NUM_LIT:5> : <EOL> self . m_logger . info ( string_to_log ) <EOL> else : <EOL> self . m_logger . debug ( string_to_log ) <EOL> return None </s>
