Python (2.7.6) Standard Log Module, python2.7.6

Source: Internet
Author: User

Python (2.7.6) Standard Log Module, python2.7.6

In addition to using the basicConfig method in the logging module to configure logs, in the logging. config module of Python, The dictConfig and fileConfig methods support Logger, Handler, and Formatter configuration through dictionaries and files respectively. The following uses an example to illustrate how to use the file configuration log, for 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

import loggingimport logging.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')

 

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.