Python (2.7.6) standard log module-Logging Configuration

Source: Internet
Author: User

In addition to using the Basicconfig method in the logging module to configure the log, the Dictconfig and Fileconfig methods in Python's Logging.config module support the configuration of Logger, Handl, and files by dictionary and file respectively. ER and Formatter. Here is an example of how to use the file configuration log, more detailed usage reference: https://docs.python.org/2/library/logging.config.html

Logging.conf

##########################################################################################[loggers]keys=root, log1[logger_root]level=debughandlers=hand01,hand02[logger_log1]handlers=hand02qualname=log1propagate=0######## ##################################################################################[handlers]keys=hand01,hand02 [Handler_hand01]class=filehandlerlevel=debugformatter=form01args= (' Myapp.log ', ' a ') [handler_hand02]class= Streamhandlerlevel=debugformatter=form01args= (Sys.stdout,) #################################################### ######################################[formatters]keys=form01[formatter_form01]format=% (asctime) s [% (threadName ) s] (% (filename) s:% (lineno) d)% (levelname) s-% (message) sdatefmt=%y-%m-%d%h:%m:%s

logging_config_demo.py

ImportLoggingImportLogging.configlogging.config.fileConfig ("logging.conf") Log1= Logging.getlogger ("Log1") Log1.debug ('This is a debug message') Log1.info ('This is an info message') log1.warning ('This is a warning message')

Python (2.7.6) standard log module-Logging Configuration

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.