Logging
ActiveLogic Python API uses Python’s built-in logging module to perform system logging. The usage of this module is discussed in detail in Python’s own documentation.
Loggers
ActiveLogic Python API provides several built-in loggers.
activelogic
The catch-all logger for messages in ActiveLogic Python API. Log messages are posted using any of the loggers below rather than this name.
activelogic.pldb.*
Log messages related to the physical connection and the pldb side of things.
activelogic.asyncapi.*
Resource-specific log messages.
Configuring Logging
Programmers can configure logging in three ways:
Creating loggers, handlers and formatters explicitly using Python code.
Creating a logging config file and reading it using fileConfig().
Creating a dictionary of log configuration and pass it to dictConfig().
The following example configures a very simple logger, a console handler, and a simple formatter using Python code:
import logging
# create logger
logger = logging.getLogger('activelogic')
logger.setLevel(logging.INFO)
# create console handler and set desired log level
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
# create formatter
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(name)s: %(message)s')
# add formatter to console handler
ch.setFormatter(formatter)
# add console handler to logger
logger.addHandler(ch)
Here’s an example of the same setup using the dictConfig format:
LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
}
},
'handlers': {
'console': {
'formatter': 'standard',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'activelogic': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False
}
}
}