For a very detailed log use please see here: http://www.cnblogs.com/dkblog/archive/2011/08/26/2155018.html
1 #Import Log Module2 ImportLogging3 #you need to import this module when setting up a log with a configuration file4 ImportLogging.config5 classMyLog:6 " "Log class for writing log information to a. txt file" "7 8 #load configuration information from Logging.cfg9 __loadcfg=logging.config.fileconfig ("Loggers/logging.ini")Ten One #gets a logger object that is the same log object when the log object is obtained elsewhere in the current program process by using the name parameter. A __dblog=logging.getlogger ('DBLog') - - @staticmethod the defAddlog (msg,logrefname=None): - " "//Add log - //1.msg: Log content - //2.logrefname: This name gets the log object, which is dblog by default. Other names to be viewed in the config file + " " - ifLogrefname is notNone: +MyLog.__dblog=Logging.getlogger (logrefname) A atMyLog.__dblog. Debug (msg)
Call Mylog.addlog (logmsg) to join the log when you use it.
Problems:
# 1. Error. Keyerror formatters is a path problem
# 2. Error GBK ... With VS2013, the new Python file is not utf-8 encoded and needs to be changed. But for this logging.ini, actually to change back to gb2312 (936). If you don't change it, you will report the mistake.
Python--logging Log