The logging of Python basics

Source: Internet
Author: User

ImportLoggingdeflogger (): Logger= Logging.getlogger ('Logger') #括号里面默认是root Logger.setlevel ('DEBUG') #设置等级是DEBUG, the number is 10,info is 20,warning is 30,error is 40,criticle is the _format= Logging. Formatter ('[% (name) s]% (asctime) s% (levelname) -8s:% (message) s') FH= Logging. Filehandler ('Log.txt', encoding='Utf-8') #文件处理器 Ch=logging. Streamhandler () #控制台处理器 Logger.addhandler (FH) logger.addhandler (CH) fh.setformatter (_format) #设置文件格式 Ch.setforma Tter (_format) #设置控制台输出格式returnLoggerdefAdd (A, b):Print('start running the Add function') logger.warning (f'a = {a},b={b}') Sumer= A +b logger.info (f'result ={sumer}')    returnSumerlogger=logger () Add (1,4)

The logging of Python basics

Related Article

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.