Differences
This shows you the differences between two versions of the page.
python_wiki:logging [2018/07/09 00:04] billdozor created |
python_wiki:logging [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Logging ====== | ||
- | |||
- | **General Information** | ||
- | |||
- | Using the logging module to output to a log file and the console. | ||
- | |||
- | ---- | ||
- | |||
- | ====== Usage ====== | ||
- | |||
- | Run the logging_example.py script to see output to the console and a log file. | ||
- | <code bash> | ||
- | ./ | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ====== The Code ====== | ||
- | |||
- | <code python logging_example.py> | ||
- | # | ||
- | |||
- | ####---- Logging Configuration ----#### | ||
- | LOGGING_CONFIG = { | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | }, | ||
- | ' | ||
- | ' | ||
- | }, | ||
- | }, | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | }, | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | }, | ||
- | }, | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | }, | ||
- | }, | ||
- | } | ||
- | ####---- End of Logging Config ----#### | ||
- | |||
- | # Logging Module with config capabilities | ||
- | import logging.config | ||
- | |||
- | # Create logging instance | ||
- | logger = logging.getLogger(__name__) | ||
- | |||
- | # Load logging configuration | ||
- | logging.config.dictConfig(LOGGING_CONFIG) | ||
- | |||
- | # Send log messages | ||
- | logger.info(" | ||
- | logger.critical(" | ||
- | </ | ||
- | |||
- | ---- | ||