Note
Click here to download the full example code
1.6. Logging and debugingΒΆ
import logging
import spydrnet as sdn
logger = logging.getLogger("spydrnet_logs")
logger.info("This is information")
logger.debug("This is debug message")
logger.warning("This is warning message")
# Turn on logging in file, and set LOG LEVEL
sdn.enable_file_logging(LOG_LEVEL="INFO", filename="execution_log_file")
logger.info("file: This is information")
logger.debug("file: This is debug message")
logger.warning("file: This is warning message")
# Dynamically turn on DEBUG for part of code
logger.handlers[1].setLevel(logging.DEBUG)
logger.info("Dynamic: This is information")
logger.debug("Dynamic: This is debug message")
logger.warning("Dynamic: This is warning message")
logger.handlers[1].setLevel(logging.INFO)
Output log file (_execution_log_file_spydrnet.log)
INFO 11_logging_mesages.py:18 (MainThread) - file: This is information
WARNING 11_logging_mesages.py:20 (MainThread) - file: This is warning message
INFO 11_logging_mesages.py:24 (MainThread) - Dynamic: This is information
DEBUG 11_logging_mesages.py:25 (MainThread) - Dynamic: This is debug message
WARNING 11_logging_mesages.py:26 (MainThread) - Dynamic: This is warning message
Total running time of the script: ( 0 minutes 0.000 seconds)