#NEWLINE# def set_logging( config , root_path = '' ) : #NEWLINE# #INDENT# 'setting logging\n\n    :param config: config dict\n    :param root_path:\n    ' #NEWLINE# colour = config [ 'class' ] [ 'stream' ] [ 'colour' ] #NEWLINE# default_format = CustomizeLog ( config [ 'format' ] ) #NEWLINE# stream_format = ( CustomizeLog ( config [ 'format' ] , width_color = True ) if ( colour and POSIX ) else default_format ) #NEWLINE# handlers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# handler = logging . StreamHandler ( sys . stderr ) #NEWLINE# handler . setFormatter ( stream_format ) #NEWLINE# handlers [ 'stream' ] = handler #NEWLINE# for ( handler_name , params ) in config [ 'handler' ] . items ( ) : #NEWLINE# #INDENT# handler_format = ( CustomizeLog ( params [ 'format' ] ) if params . get ( 'format' ) else default_format ) #NEWLINE# handler_params = config [ 'class' ] [ params [ 'class' ] ] . copy ( ) #NEWLINE# handler_params . update ( params ) #NEWLINE# logfile = ( params [ 'path' ] if params [ 'path' ] . startswith ( '/' ) else os . path . join ( root_path , params [ 'path' ] ) ) #NEWLINE# if ( not os . path . exists ( os . path . dirname ( logfile ) ) ) : #NEWLINE# #INDENT# os . makedirs ( os . path . dirname ( logfile ) ) #NEWLINE# #UNINDENT# backup_count = handler_params [ 'backup_count' ] #NEWLINE# if ( params [ 'class' ] == 'rotating_file' ) : #NEWLINE# #INDENT# max_size = multiply ( handler_params [ 'max_size' ] ) #NEWLINE# handler = RotatingFileHandler ( logfile , 'a' , max_size , backup_count , encoding = 'utf-8' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( params [ 'class' ] == 'time_rotating_file' ) : #NEWLINE# #INDENT# when = handler_params [ 'when' ] #NEWLINE# interval = handler_params [ 'interval' ] #NEWLINE# handler = TimedRotatingFileHandler ( logfile , when , interval , backup_count , encoding = 'utf-8' ) #NEWLINE# #UNINDENT# #UNINDENT# handler . setFormatter ( handler_format ) #NEWLINE# handlers [ handler_name ] = handler #NEWLINE# #UNINDENT# for ( module , params ) in config [ 'logger' ] . items ( ) : #NEWLINE# #INDENT# level = params [ 'level' ] . upper ( ) #NEWLINE# handler_names = params [ 'handler' ] . split ( ) #NEWLINE# propagate = ( params . get ( 'propagate' ) or config [ 'propagate' ] ) #NEWLINE# if ( module == 'default' ) : #NEWLINE# #INDENT# logger = logging . getLogger ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger = logging . getLogger ( module ) #NEWLINE# logger . propagate = propagate #NEWLINE# #UNINDENT# for handler_name in handler_names : #NEWLINE# #INDENT# logger . addHandler ( handlers [ handler_name ] ) #NEWLINE# #UNINDENT# logger . setLevel ( level )