Python logging module

Source: Internet
Author: User

#!/usr/bin/env python#-*-coding:utf-8-*-#@Time: 2017/12/8 0008 14:30#@Author: MingImportLogginglogging.basicconfig ( level=logging. WARNING,#greater than or equal to warning level will be loggedformat='% (asctime) s% (filename) s[line:% (lineno) d]% (levelname) s% (message) s', Datefmt='%a,%d%b%Y%h:%m:%s', filename='Myapp.log', FileMode='W',) Logging.debug ('This is debug message') Logging.info ('This is info message') logging.warning ('This is warning message') Logging.error ('This is error message') logging.critical ("This is critical message") Logging.log (logging. ERROR,'This is error message')#you can also write to the log level yourself
logging.basicconfig function Parameters: FileName: Specifies the log file name FileMode: The same as the file function, specify the open mode of the log files,'W'Or'a'Format : Specifies the formats and contents of the output, format can output a lot of useful information, as in the example above:%(Levelno) S: Print the value of the log level%(levelname) S: Print log level name%(pathname) s: Prints the path of the current execution program, which is actually sys.argv[0]%(filename) S: Print the current name of the executing program%(funcName) s: Print the current function of the log%(Lineno) d: Print the current line number of the log%(asctime) s: Time to print the log%(thread) d: Print thread ID%(threadname) s: Print thread name%(process) d: Print process ID%(message) s: Print log information datefmt: Specifies the time format, same as Time.strftime () level: Sets the log levels by default to logging. Warning log level size relationship is: CRITICAL (> ERROR (+) > WARNING (+) > INFO > DEBUG (Ten) >NOTSET (0), of course, you can define the log level yourself. Stream: Specifies the output stream that will log, can specify output to Sys.stderr,sys.stdout or file, default output to Sys.stderr, stream is ignored when stream and filename are specified simultaneously

Is wasis an errormessage 

Python logging module

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.