def instantiate( cls, streamType = "SCREEN", logLevel = "INFO" ):
try:
logging.VERBOSE = 5
logging.addLevelName(logging.VERBOSE, "VERBOSE")
logging.Logger.verbose = lambda inst, msg, *args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs)
logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg, *args, **kwargs)
cls.logger = logging.getLogger()
if logLevel not in logging._levelNames:
raise Exception( 'Invalid file level' )
cls.logger.setLevel( logging._levelNames[logLevel] )
streamType = app.config['STREAMTYPE']
if streamType == "SCREEN":
stream = logging.StreamHandler()
else:
stream = logging.FileHandler( app.config['LOGFILE'] )
formatter = logging.Formatter( '[%(levelname)-7s - %(asctime)s] %(message)s' )
stream.setFormatter( formatter )
cls.logger.addHandler( stream )
except Exception, e:
print( 'Unable to get/set log configurations. Error: %s'%( e ) )
cls.logger = None
##
# Records a message in a file and/or displays it in the screen.
# @param level - String containing the name of the log message.
# @param message - String containing the message to be recorded.
#
评论列表
文章目录