Python's Logging module summary:
1 #!/usr/bin/python2 #Encoding=utf-83 4 ImportLogging5 6Logging.basicconfig (level=logging. DEBUG,7format='% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s',8datefmt='%a,%d%b%Y%h:%m:%s',9Filename='MYTEST.log', filemode='W')Ten One #Define a Streamhandler Aconsole =logging. Streamhandler () - console.setlevel (logging.info) -Formatter = logging. Formatter ('% (name) -12s:% (levelname) -8s% (message) s') the Console.setformatter (Formatter) -Logging.getlogger ("'). AddHandler (console) - - fromLogging.handlersImportRotatingfilehandler + #Log Rollback Handler -Rthandler = Rotatingfilehandler ('MYTEST.log', maxbytes=10*1024*1024, backupcount=5) + rthandler.setlevel (logging.info) AFormatter = logging. Formatter ('%s (name) -12s:% (levelname) -8s% (message) s') at Rthandler.setformatter (Formatter) -Logging.getlogger ("'). AddHandler (Rthandler) - -Logging.debug ("DEBGU Message") -Logging.info ("Info MESG") -Logging.warning ("Warning MSG") in - #configuring logs with the Logging.conf module to #logger.conf + """ - [Loggers] the Keys=root, TEST1, TEST2 #TEST1, TEST2 * [Logger_root] $ Level=debugPanax Notoginseng handlers = HANDLER1, HANDLER2 - [Logger_test1] the handlers = HANDLER1, HANDLER2 + Qualname=test1 A progate = 0 the [Logger_test2] + handlers = HANDLER1, HANDLER2 - Qualname=test2 $ progate = 0 $ ######################################### - [Handlers] - keys=hand01,hand02,hand03 the [HANDLER_HAND01] - Class=streamhandlerWuyi Level=info the formatter=form02 - args= (Sys.stderr,) Wu [HANDLER_HAND02] - Class=filehandler About Level=debug $ formatter=form01 - Level=debug - formatter=form01 - args= (' Myapp.log ', ' a ') A [HANDLER_HAND03] + class=handlers. Rotatingfilehandler the Level=info - formatter=form02 $ args= (' Myapp.log ', ' a ', 10*1024*1024, 5) the ############################################### the [formatters] the keys=form01,form02 the [FORMATTER_FORM01] - format=% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s in datefmt=%a,%d%b%Y%h:%m:%s the [FORMATTER_FORM02] the format=% (name) -12s:% (levelname) -8s% (message) s About datefmt=%a,%d%b%Y%h:%m:%s the """ the ImportLogging the ImportLogging.config + -Logging.config.fileConfig ("logger.conf") theLogger = Logging.getlogger ("example01")Bayi theLogger.debug ('This is debug message') theLogger.info ('This is info message') -Logger.warning ('This is warning message')
Python's logging module