Industrial IoT SDK for Python Logging¶
Introduction¶
Logging of the Industrial IoT SDK for Python is implemented using the logging module by Python, which can be configured to different log levels and a custom logging format.
Usage¶
The default log level is INFO
. Configure the logging using the log_config
module in mindsphere_core
. It contains a method called setup_logging
which allows users to configure log levels and log formats.
Setting the Log Level¶
# Import log_config from mindsphere_core
import log_config from mindsphere_core
# Setting Log Level to DEBUG
logger = log_config.setup_logging(level=logging.DEBUG)
The following log level are supported:
CRITICAL
ERROR
WARNING
INFO
DEBUG
NOTSET
Setting Log Format¶
Configure the log format to log only the message or the message with time:
# Import log_config from mindsphere_core
import log_config from mindsphere_core
# Display Logs in the format : Log Message
logger = log_config.setup_logging(format="%(message)s")
# Display Logs in the format : Time - Classname - Log Level - Log Message
logger = log_config.setup_logging(format="%(asctime)s - %(name)20s - %(levelname)6s - %(message)s")
# Display Logs in the format : name: <Classname>, level - <Log Level>, time: <time>, message: <Log Message>
logger = log_config.setup_logging(format="name: %(name)s, level: %(levelname)s, time: %(asctime)s, message: %(message)s")
Disable Logging¶
Set the log level to NOTSET
to disable logging:
# Import log_config from mindsphere_core
import log_config from mindsphere_core
# To disable logging, set the Log Level to NOTSET
logger = log_config.setup_logging(level=logging.NOTSET)
Last update: April 13, 2023
Except where otherwise noted, content on this site is licensed under the Development License Agreement.