<s> """<STR_LIT>""" <EOL> import logging <EOL> import logging . handlers <EOL> import os <EOL> import socket <EOL> _ch = None <EOL> _fh = None <EOL> host = socket . gethostname ( ) <EOL> def _make_path ( logfile ) : <EOL> """<STR_LIT>""" <EOL> filepath = os . path . dirname ( logfile ) <EOL> if filepath and not os . path . exists ( filepath ) : <EOL> os . makedirs ( filepath ) <EOL> def get_logger ( name ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( name ) <EOL> if not logger . handlers : <EOL> if _ch : <EOL> logger . addHandler ( _ch ) <EOL> if _fh : <EOL> logger . addHandler ( _fh ) <EOL> return logger <EOL> def setup_logging ( <EOL> stream = True , <EOL> logfile = None , <EOL> stream_level = logging . INFO , <EOL> file_level = logging . ERROR <EOL> ) : <EOL> """<STR_LIT>""" <EOL> formatter = logging . Formatter ( <EOL> "<STR_LIT>" . format ( host ) <EOL> ) <EOL> if stream : <EOL> global _ch <EOL> _ch = logging . StreamHandler ( ) <EOL> _ch . setLevel ( stream_level ) <EOL> _ch . setFormatter ( formatter ) <EOL> logging . getLogger ( '<STR_LIT>' ) . addHandler ( _ch ) <EOL> if logfile : <EOL> _make_path ( logfile ) <EOL> global _fh <EOL> _fh = logging . FileHandler ( logfile ) <EOL> _fh . setLevel ( file_level ) <EOL> _fh . setFormatter ( formatter ) <EOL> logging . getLogger ( '<STR_LIT>' ) . addHandler ( _fh ) </s>
