Logging with the JS7 Logger

JS7 - GraalVM Python Jobs are based on Oracle® GraalVM and can use the JS7 Logger like this:

FEATURE AVAILABILITY STARTING FROM RELEASE 2.8.2

Example for implementation of JS7Job with Python
class JS7Job(js7.Job):
    def processOrder(self, js7Step):
        logger = js7Step.getLogger()
        
        logger.info("logging some information")
        logger.warn(".. logging some warning")
        logger.error(".. logging some error")
        logger.debug(".. logging some debug output")

        # do some stuff


Explanation:

  • The js7Step.getLogger() object is provided that offers related methods for logging.
  • By default output of info(), warn() and debug() methods is written to the stdout channel, output by error() is written to stderr.
    • The argument log_level can be used for a job to specify the log level:
      • log_level = info : default, no debug output enabled.
      • log_level = debug : includes debug output
    • For details see  JS7 - JITL Common Variables.
  • For details see JS7 - Job API.

Logging with the Python Console Logger

Basically the Python print(), logging.info(), logging.warning() etc. methods cannot be used as they directly address the stdout channel. As a result use of the methods writes output to the JS7 Agent's stdout channel and to its ./logs/watchdog.log file.

It is an option to override the above logging methods and to map them to js7Step.getLogger() methods like this:

Example for implementation of Python Logger override
import builtins, logging

def logging_override(js7Step):
    builtins.print = js7Step.getLogger().info
    logging.info = js7Step.getLogger().info
    logging.warning = js7Step.getLogger().warn
    logging.error = js7Step.getLogger().error
    logging.debug = js7Step.getLogger().debug

class JS7Job(js7.Job):
    def processOrder(self, js7Step):
        logging_override(js7Step)
        logging.warning("some warning")


To make the override globally available users can add it to a JS7 - Script Include.


The Script Include can be referenced from a job using the syntax: ##!include <name-of-script-include>

As a result jobs can use the Python Console Logger as usually:

Example for implementation of JS7Job with Python
##!include Python-Logging

class JS7Job(js7.Job):
    def processOrder(self, js7Step):
        # Overriding print and Python logging via the 'logging_override' function.
        logging_override(js7Step)
        print(".. printing some information")
        logging.info(".. logging some information")
        logging.warning(".. logging some warning")
        logging.error(".. logging some error")
        logging.debug(".. logging some debug output")

        # do some stuff

Resources