Primary use of the Python-logging module

Source: Internet
Author: User

This article is suitable for just contact with the logging module, want to quickly use and see the effect of children's shoes. If you want to fully understand the logging module, please go to

directly on the code + comment

#1. Import Module LoggingImportLogging#2. Create a Logger instanceLogger = Logging.getlogger (__name__)#3. Configure log properties (the level of logs that need to be printed)Logger.setlevel (logging. DEBUG)#4. Create an handler instance (if you want to save the log file to your hard disk)Handler = logging. Filehandler ("Log.txt")#5. Add log Formatformat="% (asctime) s% (name) s% (LevelName) s--% (message) s"Handler.setformatter (logging. Formatter (format))#6. Generate Log FilesLogger.addhandler (handler)#7. Write Log ContentsLogger.info ("Info") Logger.debug ("Debug") logger.warning ("Waring") Logger.info ("Infofofofof")

The contents of the generated log file:

Another: Now the priority of Logging.basicconfig, Logger.setlevel, handler.setlevel a bit vague, welcome to Exchange ~

Declaration: Original article, welcome reprint, Reprint please indicate the source http://www.cnblogs.com/kaerxifa/p/8693661.html

Primary use of the Python-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.