#!/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