<s> """<STR_LIT>""" <EOL> import sys <EOL> import time <EOL> import threading <EOL> class _Log : <EOL> """<STR_LIT>""" <EOL> ERROR = - <NUM_LIT:2> <EOL> WARN = - <NUM_LIT:1> <EOL> QUIET = <NUM_LIT:0> <EOL> NORMAL = <NUM_LIT:1> <EOL> VERBOSE = <NUM_LIT:2> <EOL> DEBUG = <NUM_LIT:3> <EOL> start_time = time . time ( ) <EOL> def __init__ ( self ) : <EOL> self . log_level = _Log . NORMAL <EOL> self . _err = sys . stderr <EOL> self . _out = sys . stderr <EOL> self . lock = threading . Lock ( ) <EOL> def increase_verbosity ( self ) : <EOL> self . lock . acquire ( ) <EOL> try : <EOL> self . log_level = min ( self . log_level + <NUM_LIT:1> , _Log . DEBUG ) <EOL> finally : <EOL> self . lock . release ( ) <EOL> def decrease_verbosity ( self ) : <EOL> self . lock . acquire ( ) <EOL> try : <EOL> self . log_level = max ( self . log_level - <NUM_LIT:1> , _Log . ERROR ) <EOL> finally : <EOL> self . lock . release ( ) <EOL> def is_on ( self , level ) : <EOL> """<STR_LIT>""" <EOL> return self . log_level >= level <EOL> def _timestamp ( self ) : <EOL> """<STR_LIT>""" <EOL> retval = [ ] <EOL> if self . log_level >= _Log . DEBUG : <EOL> retval . append ( '<STR_LIT>' % ( time . time ( ) - self . start_time , ) ) <EOL> return '<STR_LIT>' . join ( retval ) <EOL> def _write ( self , out , * args ) : <EOL> """<STR_LIT>""" <EOL> timestamp = self . _timestamp ( ) <EOL> s = '<STR_LIT:U+0020>' . join ( map ( str , args ) ) <EOL> lines = s . split ( '<STR_LIT:\n>' ) <EOL> if lines and not lines [ - <NUM_LIT:1> ] : <EOL> del lines [ - <NUM_LIT:1> ] <EOL> self . lock . acquire ( ) <EOL> try : <EOL> for s in lines : <EOL> out . write ( '<STR_LIT>' % ( timestamp , s , ) ) <EOL> out . flush ( ) <EOL> finally : <EOL> self . lock . release ( ) <EOL> def write ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> self . _write ( self . _out , * args ) <EOL> def error ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . is_on ( _Log . ERROR ) : <EOL> self . _write ( self . _err , * args ) <EOL> def warn ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . is_on ( _Log . WARN ) : <EOL> self . _write ( self . _out , * args ) <EOL> def quiet ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . is_on ( _Log . QUIET ) : <EOL> self . _write ( self . _out , * args ) <EOL> def normal ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . is_on ( _Log . NORMAL ) : <EOL> self . _write ( self . _out , * args ) <EOL> def verbose ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . is_on ( _Log . VERBOSE ) : <EOL> self . _write ( self . _out , * args ) <EOL> def debug ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . is_on ( _Log . DEBUG ) : <EOL> self . _write ( self . _out , * args ) <EOL> logger = _Log ( ) </s>
