#coding: Utf-8
Import logging
Logger = Logging.getlogger ("Simple_example") #可以说是日志信息的名字吧, can be casually named
Logger.setlevel (logging. DEBUG) #这个是全局的输出水平, the level of file output and console output is above this level to output.
#输出到屏幕
ch = logging. Streamhandler ()
Ch.setlevel (logging. WARNING) #这个水平控制台输出水平, regardless of what is set here, the output level must be above the global level. For example, the global level is error, even if the warning-is set here, the console can only output information that is error greater than or equal to error
#输出到文件
FH = logging. Filehandler ("Log2.log") #日志文件的命名
Fh.setlevel (logging. DEBUG)
#设置日志格式
Fomatter = logging. Formatter ('% (asctime) s-% (name) s-% (levelname) s-% (module) s:% (message) s ')
Ch.setformatter (Fomatter)
Fh.setformatter (Fomatter)
Logger.addhandler (CH)
Logger.addhandler (FH)
Logger.debug ("Debug Message")
Logger.info ("info message")
Logger.warning ("warning message")
Logger.error ("error message")
Logger.critical ("critical Message")
Python3 Logging Notes