Python basic syntax-logging

Source: Internet
Author: User

Describe:

Many programs have logging requirements, and the information contained in the log is a normal program access log, there may be errors, warnings and other information output, Python's logging module provides a standard log interface, you can use it to store various formats of the log.

The logging log can be divided into 5 levels:

    • Debug ()
    • Info ()
    • Warning ()
    • Error ()
    • Critical ()
Simple usage:
Logging.debug ('Degbug Message') Logging.info ('Info Message') logging.warning ('Hello') Logging.error ('error Message') logging.critical ('Critical Message')>>>output:WARNING:root:helloERROR:root:error messageCRITICAL:root:critical Message
Level = Warning
Logger file:
ImportLogginglogging.basicconfig ( level=logging. DEBUG, Format='% (asctime) s% (filename) s-% (levelname) s-% (message) s', Datefmt='%a,%d%b%Y%h:%m:%s', filename='Test.log', FileMode='W') Logging.debug ('Degbug Message') Logging.info ('Info Message') logging.warning ('Hello') Logging.error ('error Message') logging.critical ('Critical Message')>>>output:test.logWed,Mar 2018 22:58:03 Logging_module.py-debug-Degbug messagewed,Mar 2018 22:58:03 Logging_module.py-info-Info messagewed,Mar 2018 22:58:03 Logging_module.py-warning-hellowed,Mar 2018 22:58:03 Logging_module.py-error-error messagewed,Mar 2018 22:58:03 logging_module.py-critical-critical Message

Python basic syntax-logging

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.