#NEWLINE# def setup_logger( config = None ) : #NEWLINE# #INDENT# 'Initialize logging facility' #NEWLINE# if ( config is None ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( not ( config . has_option ( 'server' , 'loglevel' ) or config . has_option ( 'server' , 'logfile' ) ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# logfile = None #NEWLINE# loglevel = 'NOTSET' #NEWLINE# if config . has_option ( 'server' , 'loglevel' ) : #NEWLINE# #INDENT# loglevel = config . get ( 'server' , 'loglevel' ) #NEWLINE# if ( loglevel not in LOGLEVELS . keys ( ) ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Invalid server configuration (server.loglevel).' ) #NEWLINE# #UNINDENT# if ( not config . has_option ( 'server' , 'logfile' ) ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Invalid server configuration (server.loglevel set,                but server.logfile missing).' ) #NEWLINE# #UNINDENT# #UNINDENT# if config . has_option ( 'server' , 'logfile' ) : #NEWLINE# #INDENT# if ( not config . has_option ( 'server' , 'loglevel' ) ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Invalid server configuration (server.logfile set,                but server.loglevel missing).' ) #NEWLINE# #UNINDENT# logfile = config . get ( 'server' , 'logfile' ) #NEWLINE# #UNINDENT# if ( ( loglevel != 'NOTSET' ) and ( logfile is None ) ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Invalid server configuration             (server.loglevel set, but server.logfile is not).' ) #NEWLINE# #UNINDENT# logging . basicConfig ( level = LOGLEVELS [ loglevel ] , filename = logfile , datefmt = TIME_FORMAT , format = MSG_FORMAT ) #NEWLINE# LOGGER . info ( ( 'Logging initialized (level: %s).' % loglevel ) ) #NEWLINE# if ( loglevel == 'DEBUG' ) : #NEWLINE# #INDENT# LOGGER . info ( 'CGI debugging enabled.' ) #NEWLINE# import cgitb #NEWLINE# cgitb . enable ( )