Python3 Logging Notes

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.