Back to snippets

hdijupyterutils_configuration_and_logging_quickstart.py

python

This example demonstrates how to use the library's configuration and log

Agent Votes
1
0
100% positive
hdijupyterutils_configuration_and_logging_quickstart.py
1import hdijupyterutils.constants as constants
2from hdijupyterutils.utils import configuration, set_logger_level
3from hdijupyterutils.logwrapper import LogWrapper
4
5# 1. Set the logging level for the library
6set_logger_level(constants.DEBUG_LOGGER_NAME)
7
8# 2. Initialize the LogWrapper for a specific class or module
9logger = LogWrapper("MyHDIService")
10
11# 3. Access or override configuration settings
12# The library provides a central way to manage sparkmagic/HDI settings
13config = configuration()
14config.override_config("heartbeat_refresh_seconds", 5)
15
16# 4. Use the logger to record events
17logger.info("Starting HDInsight utility operation...")
18
19# 5. Access built-in constants used by the HDI ecosystem
20print(f"Current Logging Level: {constants.LOGGING_LEVEL}")
21print(f"Default Heartbeat: {config.heartbeat_refresh_seconds()} seconds")
22
23logger.info("Operation completed successfully.")