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')