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