<s> """<STR_LIT>""" <EOL> import inspect <EOL> import os <EOL> import sys <EOL> import time <EOL> import traceback <EOL> import logging <EOL> import logging . handlers <EOL> import paths <EOL> STREAM_STRING_FORMAT = '<STR_LIT>' <EOL> FILE_STRING_FORMAT = '<STR_LIT>' <EOL> def is_test_stack_frame ( frame ) : <EOL> path = frame [ <NUM_LIT:1> ] <EOL> return "<STR_LIT>" in path <EOL> def is_running_in_test ( ) : <EOL> current_stack = inspect . stack ( ) <EOL> return any ( map ( is_test_stack_frame , inspect . stack ( ) ) ) <EOL> class IceLevelTagFilter ( logging . Formatter ) : <EOL> def _tag_for_level ( self , levelno ) : <EOL> name = logging . getLevelName ( levelno ) <EOL> return "<STR_LIT>" if levelno is logging . INFO else "<STR_LIT>" % name <EOL> def filter ( self , record ) : <EOL> record . leveltag = self . _tag_for_level ( record . levelno ) <EOL> return True <EOL> def create_stream_handler ( level ) : <EOL> sh = logging . StreamHandler ( ) <EOL> sh . setLevel ( level ) <EOL> sh . addFilter ( IceLevelTagFilter ( ) ) <EOL> sh . setFormatter ( logging . Formatter ( STREAM_STRING_FORMAT ) ) <EOL> return sh <EOL> def create_file_handler ( level ) : <EOL> path = paths . log_file_location ( ) <EOL> directory = os . path . dirname ( path ) <EOL> if not os . path . exists ( directory ) : <EOL> os . makedirs ( directory ) <EOL> fh = logging . handlers . RotatingFileHandler ( <EOL> filename = path , <EOL> maxBytes = <NUM_LIT> , <EOL> backupCount = <NUM_LIT:5> ) <EOL> fh . setLevel ( level ) <EOL> fh . setFormatter ( logging . Formatter ( FILE_STRING_FORMAT ) ) <EOL> return fh <EOL> def create_logger ( ) : <EOL> sh = create_stream_handler ( logging . INFO ) <EOL> fh = create_file_handler ( logging . DEBUG ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . setLevel ( logging . DEBUG ) <EOL> if not is_running_in_test ( ) : <EOL> logger . addHandler ( sh ) <EOL> logger . addHandler ( fh ) <EOL> return logger <EOL> logger = create_logger ( ) </s>
