In Python,LoggingThe module mainly deals with logs. The so-called log, can be understood as the software in the course of operation, the recorded some of the operational information software developers can add logs according to their own needs, logs can help software developers understand the operation of the software information, the maintenance of the software is particularly important. Log level: Levels when it ' s used DEBUG detailed Information,typi Cally of interest if diagnosing problems INFO confirmation that things is working as Expected WARNING an indication that something unexpected happended,or indicative of some probl EM in the near future. The software is still working as expected ERROR Due to a more serious problem,the software ha s not been able to perform some Funciton CRITICAL A serious error, indication then the program I Tself may unable to continue running. The default level is WARNING. Here is a example:import logging logging.info (' This is an info log! ') Logging.warning (' This is a warn log! ') You can see the result:WARNING:root:this is a warN log! If you want to see some logs with lower levels, you can do this: Here's an example:import logging logging.basicconfig (filename = ' C:\\test\\hongten.log ', level = logging. Debug) Logging.debug (' This is a debug log! ') Logging.info (' This was an info log! ') Logging.warning (' This is a warn log! ') You can see the result:DEBUG:root:this is a DEBUG log! INFO:root:this is an info log! WARNING:root:this is a warn log! If you want to format the output log, you can do this: Here's an example:import logging logging.basicconfig (format = '% (levelname) s:% (message) S ', level = logging. Debug) Logging.debug (' This is a debug log! ') Logging.info (' This was an info log! ') Logging.warning (' This is a warn log! ') You can see the result:DEBUG:this is a DEBUG log! Info:this is an info log! Warning:this is a warn log! The following is the LogRecord attributes, which needs to be used when formatting the output log: Attribute name format De scription args shouldn ' t need toFormat the tuple of arguments merged into MSG to produce message. This yourself. Asctime% (asctime) s time format created% (CR eated) s creation time filename% (filename) s File name LevelName% (levelname) s log level Levelno % (Levelno) s log ID number Lineno% (Lineno) s Line number module% (module) s module name Mescs % (Mescs) s millisecond portion of the time when the LogRecord is created. Message% (message) s log information name% (NA ME) s Log name pathname% (pathname) s file absolute path Process% s Progress ID processName% (processName) s process name relativecreated% (relativecreated) s Time in milliseconds when the LogRecord is created, Relative to the time of the logging module was loaded. Thread% (thread) s threads ID threadname% (th Readname) s thread name
Python Logging usage