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
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()anddebug()methods is written to the stdout channel, output byerror()is written to stderr.- The argument
log_levelcan 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.
- The argument
- 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:
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.
- Download sample files (or copy from above examples):
- Download override of Console Logger from Script Include (upload .json): Python-Logging.includescript.json
- Download the workflow (upload .json): pdPythonLogging.workflow.json
- In the Configuration->Inventory view the override is configured like this:
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:
##!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
