python-Log Module

Source: Internet
Author: User

1. The role of the log:

In the case of software or system errors, you can quickly locate the error through the log, so as to locate the problem and solve the problem.

2. Level of log:
    • DEBUG Most verbose log information, typical application scenario is problem diagnosis
    • Info details are second only to debug, and typically only key node information is logged to confirm that everything works as we expect
    • WARNING information that is logged when something is not expected (for example, the disk has less free space), but the application is still functioning
    • Error logging information because of a more serious problem that causes some features to not function properly
    • CRITICAL information that is logged when a critical error occurs that causes the application to continue running
3. Log field information and log format
    • Event Occurrence Time
    • Where the event occurred
    • Severity of the event-log level
    • Event Content
4.logging Module

The log level that is used by the logging function that is provided by the logging module is WARNING so that only WARNING the level of logging and log records that are larger than its ERROR and level are CRITICAL output, and less than its DEBUG and INFO The level of logging was discarded.

  

>>>:logging.warning (' Warning bug ')

Output: WARNING:root:warning bug

Log level: Logger Name: Log content

5. Logging.basicconfig () function

This method is used to make some basic configuration for the logging log system.

Sys.stdout Standard Output

Sys.stderr standard Error

The three configuration items, filename, stream, and handlers, can only have one presence, 2 or 3 cannot occur at the same time, or a ValueError exception will be thrown.

  

ImportLogging#Logging.basicconfig (level=logging. DEBUG) #指定日志级别#Log_format = "% (asctime) s-% (levelname) s-% (message) S" # Specifies the occurrence time, level name, log information#logging.basicconfig (filename= ' Log.log ', level=logging. Debug,format=log_format)Log_format="% (asctime) s-% (levelname) s-% (message) s"Date_format="%y/%m/%d%h:%m:%s%p"logging.basicconfig (filename='Log.log', level=logging. DEBUG, Format=log_format, datefmt=date_format) Logging.debug ('Debug Log') logging.warning ('warning Bug')
07/23/2018 21:51:32 pm-debug- DEBUG log07/23/2018 21:51:32 pm-warning- WARNING bug2018/07/23 21:52 : Pm-debug- DEBUG log2018/07/23 21:52:54 pm-warning-warning Bug

python-Log 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.