Page History
...
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
(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.
- Download sample files (or copy from above examples):
- Download override of Console Logger from Script Include (upload .json): JavaScript-Logging.includescript.json
- Download the workflow (upload .json): pdJavaScriptLogging.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>
Subsequently jobs can use the JavaScript Console Logger as usedJavaScript Jobs can use the Console Logger like this:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job { processOrder(js7Step) { print//!include JavaScript-Logging print('.. printing some information'); console.info('.. logging some information'); console.log('.. logging some information'); console.warn('.. logging some warning'); console.error('.. logging some error'); console.debug('.. logging some debug output'); // do some stuff } } |
...