Python development _ logging _ log processing

Source: Internet
Author: User

Log processing operations may occur in many programming languages, and python is no exception...

Next let's take a look atModule

The module mainly processes logs. The so-called logs can be understood as some running information recorded during software operation. Software developers can add logs as needed, logs can help software developers understand the running information of software, especially for software maintenance. Log Level: Level When it's used DEBUG detailed information, typically of interest only when diagnosing problems INFO confirmation that things are working as expected WARNING An indication that something unexpected happended, or indicative of some problem in the near future. the software is still working as expected ERROR Due to a more serous problem, the software has not been able to perform some funciton Critical a serious error, indication that the program itself may be unable to continue running. The default level is WARNING. Here is an 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 low-level logs, you can do this: Here is an Example: import logging. basicConfig (filename = 'C: \ test \ hongten. log', level = logging. DEBUG) logging. debug ('this is a debug log! ') Logging.info ('this is 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 is an Example: import logging. basicConfig (format = '% (levelname) s: % (message) s', level = logging. DEBUG) logging. debug ('this is a debug log! ') Logging.info ('this is 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 must be used when formatting The output log: Attribute name Format Description args You shouldn't need to format The tuple of arguments merged into msg to produce message. this yourself. asctime % (asctime) s time format created % (created) s creation time filename % (filename) s file name levelname % (levelname) s log level levelno % (levelno) s log ID number lineno % (lineno) s row number module % (module) s module name mescs % (mescs) s Millisecond portion of the time when the LogRecord was created. message % (message) s log information name % (name) s log name pathname % (pathname) s file absolute path process % (process) s process id processName % (processName) s process name relativeCreated % (relativeCreated) s Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded. thread % (thread) s thread id threadName % (threadName) s thread name

Here is my demo:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32,    >>> ================================ RESTART ================================>>> 2013-08-26 11:01:58,076 - root - DEBUG - this 2013-08-26 11:01:58,080 - root - INFO - this 2013-08-26 11:01:58,085 - root - WARNING - this 2013-08-26 11:01:58,088 - root - ERROR - this 2013-08-26 11:01:58,091 - root - CRITICAL - this >>> 

                                                                                                               logging.warning(     logging.info(             logging.basicConfig(filename = path, level =     logging.debug(     logging.info(     logging.warning(            logging.warning(, 3, 4, 3+4            logging.basicConfig(format=, level=     logging.debug(     logging.info(     logging.warning(                                              logging.config.fileConfig(     logger = logging.getLogger(     logger.debug(     logger.info(     logger.warn(     logger.error(     logger.critical(                 ( * 50          ( * 50          ( * 50          ( * 50          ==      main()

 

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.