Python Logging usage

Source: Internet
Author: User
Tags time in milliseconds

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

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.