<s> import sys <EOL> from . . util . singleton import Singleton <EOL> from . . util . compat import with_metaclass <EOL> from . color import Color <EOL> from . level import Level <EOL> class Messenger ( with_metaclass ( Singleton , object ) ) : <EOL> def __init__ ( self , level = Level . LOWINFO ) : <EOL> self . set_level ( level ) <EOL> def set_level ( self , level ) : <EOL> self . _level = level <EOL> def log ( self , level , message ) : <EOL> if ( level >= self . _level ) : <EOL> print ( '<STR_LIT>' % ( self . _color ( level ) , message , self . _reset ( ) ) ) <EOL> def debug ( self , message ) : <EOL> self . log ( Level . DEBUG , message ) <EOL> def lowinfo ( self , message ) : <EOL> self . log ( Level . LOWINFO , message ) <EOL> def info ( self , message ) : <EOL> self . log ( Level . INFO , message ) <EOL> def warning ( self , message ) : <EOL> self . log ( Level . WARNING , message ) <EOL> def error ( self , message ) : <EOL> self . log ( Level . ERROR , message ) <EOL> def _color ( self , level ) : <EOL> '''<STR_LIT>''' <EOL> if not sys . stdout . isatty ( ) : <EOL> return '<STR_LIT>' <EOL> elif level < Level . DEBUG : <EOL> return '<STR_LIT>' <EOL> elif Level . DEBUG <= level < Level . LOWINFO : <EOL> return Color . YELLOW <EOL> elif Level . LOWINFO <= level < Level . INFO : <EOL> return Color . BLUE <EOL> elif Level . INFO <= level < Level . WARNING : <EOL> return Color . GREEN <EOL> elif Level . WARNING <= level < Level . ERROR : <EOL> return Color . MAGENTA <EOL> elif Level . ERROR <= level : <EOL> return Color . RED <EOL> def _reset ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not sys . stdout . isatty ( ) : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return Color . RESET </s>
