<s> __all__ = [ '<STR_LIT>' ] <EOL> import asn1 <EOL> import coro <EOL> import time <EOL> class FileLogger : <EOL> time_format = '<STR_LIT>' <EOL> def __init__ ( self , f ) : <EOL> self . f = f <EOL> def log ( self , * data ) : <EOL> line = '<STR_LIT:U+0020>' . join ( [ repr ( x ) for x in data ] ) <EOL> self . f . write ( "<STR_LIT>" % ( time . strftime ( self . time_format ) , line ) ) <EOL> self . f . flush ( ) <EOL> class StderrLogger ( FileLogger ) : <EOL> def __init__ ( self ) : <EOL> FileLogger . __init__ ( self , coro . saved_stderr ) <EOL> class SysLogger : <EOL> def __init__ ( self , path = '<STR_LIT>' , facility = <NUM_LIT:16> , level = <NUM_LIT:6> ) : <EOL> self . sock = coro . sock ( coro . AF . UNIX , coro . SOCK . DGRAM ) <EOL> self . sock . connect ( path ) <EOL> self . encoded = ( facility << <NUM_LIT:3> ) | level <EOL> def log ( self , * data ) : <EOL> line = '<STR_LIT:U+0020>' . join ( [ repr ( x ) for x in data ] ) <EOL> self . sock . send ( '<STR_LIT>' % ( self . encoded , line ) ) <EOL> class ComboLogger : <EOL> def __init__ ( self , * loggers ) : <EOL> self . loggers = loggers <EOL> def log ( self , * data ) : <EOL> for logger in self . loggers : <EOL> logger . log ( * data ) <EOL> class Facility : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def __call__ ( self , * data ) : <EOL> log ( self . name , * data ) <EOL> def exc ( self ) : <EOL> log ( self . name , '<STR_LIT>' , coro . traceback_data ( ) ) <EOL> class NoFacility : <EOL> def __call__ ( self , * data ) : <EOL> log ( * data ) <EOL> def exc ( self ) : <EOL> log ( '<STR_LIT>' , coro . traceback_data ( ) ) <EOL> class StderrRedirector : <EOL> def __init__ ( self ) : <EOL> self . log = Facility ( '<STR_LIT>' ) <EOL> def write ( self , data ) : <EOL> self . log ( data ) <EOL> def redirect_stderr ( ) : <EOL> global stderr <EOL> stderr = StderrRedirector ( ) <EOL> import sys <EOL> sys . stderr = stderr <EOL> coro . write_stderr = stderr . write <EOL> coro . print_stderr = stderr . write <EOL> coro . _coro . write_stderr = stderr . write <EOL> coro . _coro . print_stderr = stderr . write <EOL> the_logger = StderrLogger ( ) <EOL> def set_logger ( logger ) : <EOL> global the_logger <EOL> the_logger = logger <EOL> def log ( * data ) : <EOL> the_logger . log ( * data ) </s>
