Skip to main content
Scripting Toolkit logs internal operations using the Python logging module. Scripting Toolkit defines a hierarchy of loggers which log the following information:
  • GDL.core: Requests to Granta MI, including retries and elapsed time per request.
  • GDL.http: HTTP status codes and full SOAP request and response content.
  • GDL.cache: Streamlined layer caching information, including cache misses and cache clearing operations.
Python Logger objects are hierarchical, with levels in the hierarchy being defined by the . character. Messages are passed from lower level Logger objects to higher level ones. As a result, it is possible to access all log messages via the GDL logger. By default, these messages are not output. To output the messages generated by this package and to add your own log messages, you should:
  1. Create a logger for your script.
  2. Attach a handler to the logger.
The following sub-sections provide simple best practice for logging with this package. For more information about Python logging in general, see the Python documentation:

Creating a logger

The GDL logger can be accessed in two ways. The first is via the get_foundation_logger() function:
The second is by fetching the GDL logger by name using the Python getLogger() function:
The second option is more flexible since it allows access to more granular loggers. For example, to access only the GDL.core logger:
The root of the Python logger hierarchy is the root logger, which contains all messages logged by all loggers in a Python instance. To create an instance of the root logger, do not specify a logger name when using getLogger():
Logger objects only handle messages at or above a defined severity level. All new logger objects have a default log level of WARNING, so they ignore messages of INFO or lower. To change a logger’s log level, use Logger.setLevel():
You can then add log statements to the logger at a certain log level as follows:

NOTE

Until a log handler is attached, no log messages are emitted.

Attaching a handler

There are two main types of handlers provided by the Python logging library: FileHandler handlers and StreamHandler handlers. A FileHandler is used to write log messages to a file on disk, and a StreamHandler is used to write log messages to stderr or stdout. To add a StreamHandler handler to the root logger from the previous section, use the following code:
It is possible to also log files to disk by using a FileHandler. The following example shows the creation of a FileHandler handler with a filename based on the current date:
%(name)s includes the name of the logger to which the message was logged, which enables a single log file to be used to capture information from all Scripting Toolkit loggers and loggers created for user code.

Additional logging

The MI Scripting Toolkit underlying C libraries also perform their own additional logging separate to the Python logging. These logs can be found in the following locations:
  • Windows: %LOCALAPPDATA%\Granta\Granta MI\ScriptingToolkit
  • Linux: ~/.appdata/Granta/Granta MI/ScriptingToolkit

Versionchanged

Changed in version 4.2: Log location changed