Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

JS7 - JavaScript Jobs can use the JS7 Logger like this:

Code Block
languagejs
titleExample for implementation of JS7Job with JavaScript
linenumberstrue
class JS7Job extends js7.Job {

	processOrder(js7Step) {
		js7Step.getLogger().info('logging 'hellosome worldinformation' ); 		
		js7Step.getLogger().warn('.. logging asome warning');
		js7Step.getLogger().error('.. logging ansome error');
		js7Step.getLogger().debug('.. logging some debug output');

		// do some stuff
    }
}

...

  • 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 JavaScript Console Logger

Basically the JavaScript methods  print(), console.log(), console.info(), console.warn() 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:

Code Block
languagejs
titleExample for implementation of JavaScript Console Logger override
linenumberstrue
(function(){

    print = function() {
		js7Step.getLogger().info(arguments[0]);
    }

    console.log = function() {
		js7Step.getLogger().info(arguments[0]);
    }

    console.info = function() {
		js7Step.getLogger().info(arguments[0]);
    }

    console.warn = function() {
		js7Step.getLogger().warn(arguments[0]);
    }

    console.error = function() {
		js7Step.getLogger().error(arguments[0]);
    }

    console.debug = function() {
		js7Step.getLogger().debug(arguments[0]);
    }
})();  


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

Image Added


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

As a result jobs can use the JavaScript Console Logger as usuallyJavaScript Jobs can use the Console Logger like this:

Code Block
languagejs
titleExample for implementation of JS7Job with JavaScript
linenumberstrue
class JS7Job extends js7.Job {

	processOrder(js7Step) {
		console
//!include JavaScript-Logging
        print('.. printing some information');
        console.info('.. logging ansome information');
        console.log('.. logging ansome information');
		console.warn('.. logging asome warning');
		console.error('.. logging ansome error');
		console.debug('.. logging some debug output');

        // do some stuff
    }
}

...