Python's logging module

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.