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