The shell record log, eyeful flower of the redirect in line with, looked very uncomfortable there is no! I like Python, just like the feeling of buying a flashlight and a spare battery ready. Logging module is very simple, import module, define the log format. The log can be recorded in the Code through Logging.info (), logging.warning (), Logging.debug (). And immediately feel the whole person a lot better ...
Import Logginglogging.basicconfig (level=logging. DEBUG, format= '% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s ', datefmt = '%a,%d%b%Y%h:%m:%s ', filename= ' MyLog.log ', filemode= ' a ') logging.info ("This is the logging module Recorded info ") Logging.debug (" This is the debug information for the Logging module ") logging.warning (" This is warning information for the logging module ")
The log output is as follows:
Thu, 17:24:43 1.py[line:12] Info This is the logging module recorded info
Thu, 17:24:43 1.py[line:13] Debug This is the debug information for the logging module
Thu, 17:24:43 1.py[line:14] WARNING This is logging information for the WARNING module
This article is from the "Candle Shadow Red" blog, be sure to keep this source http://gccmx.blog.51cto.com/479381/1612082
Use of the Python logging module logging