Skip to content

Logging to the ticket workspace

It is possible to write log lines to the ScriptLog output in the ticket workspace. This can be done by using the loggingService. The Logging service allows to setup an outgoing stream where log messages can be sent.

This can be pretty useful to give users of an openOBD function some idea about what is going on when running a script. Apart from informing the user, it can also be helpful to have some form of trace when a function fails for some reason. Of course, this can also be done locally, but extra information for the end user is always helpful.

Logging initialization

The service integrates seamlessly with the standard logging library module of Python. When you want to initialize this logging module with the openOBD logging service you can make a single call at the start of your openOBD function:

  • self.enable_logging_to_scriptlog()

When the module is initialized, all the lines in your script of the form self.logger.info("msg") are send to the ScriptLog tab in the ticket workspace.

The following log levels are defined in the logging service:

Field Description
DEBUG For debug lines that you normally do not want to show
INFO For lines that you want to show under normal operation
WARNING For signalling a potential problem, but the function can continue executing
ERROR An error in function execution

Python example

In the following Python example we do send log information to the ScriptLog of the ticket workspace. We have an example with the default log level 'INFO'. Just do not provide a log level as argument and use:

  • self.enable_logging_to_scriptlog()

And we have an example where we set the log level to 'DEBUG', this can be done by providing the log level as argument, like:

  • self.enable_logging_to_scriptlog('DEBUG')

Enable logging to ScriptLog

from openobd import *


class LoggingExample(OpenOBDFunction):

    def run(self):
        self.enable_logging_to_scriptlog()

        self.logger.debug("Show (depending on level) a DEBUG line")
        self.logger.info("Show an INFO line")
        self.logger.warning("Show a WARNING line")
from openobd import *


class LoggingExample(OpenOBDFunction):

    def run(self):
        self.enable_logging_to_scriptlog('DEBUG')

        self.logger.debug("Show (depending on level) a DEBUG line")
        self.logger.info("Show an INFO line")
        self.logger.warning("Show a WARNING line")

Depending on the log level ('DEBUG' or 'INFO') the output in the ticket workspace will look like this:

ScriptLog

Switch log level

It is possible to switch the log level somewhere in the middle of your openOBD function by using self.logger.setLevel('INFO')