Project

Contents

Issue #00005566

Added WGA.Logger(name) to create named Log4j-Loggers.
Feature/Improvement

If you use log.info/warn/debug(message) in your code, the default WGA logger will be used to log your messages. Because the default log level of this logger is "info", log.debug(message) will never appear in the console.

During development however you need debug messages.

Most developers therefore use log.info() instead of log.debug() during development and remove all log.info-s when deploying to production server.

We now added the possibility to use your own logger in TMLScript by using the new WGA.Logger(name) method.

WGA.Logger(name) returns a WGALogger object, that has two usefull methods

getLogger() // returns the Log4J Logger object
setLevel(loglevel)  // sets the log level for this logger
    // possible values are "debug", "info", "warn" and "error"

Sample:

var log = WGA.Logger("test").getLogger();
log.info("info");
log.debug("debug");
...

This creates a custom logger with effective name "wga.test". The default log-level still is "info" so the debug message will still not appear on the console. You can however now change this in two ways:

1) Use

WGA.Logger("test").setLevel("debug")

somewhere in your script to activate debug messages.

2) Start OpenWGA with system option

-Dde.innovationgate.wga.debug=wga.test

The second method is preferred as you don't need to change your code when going live.

If you need to debug a production server you can temporary enable debugging via TMLScript-Console by just executing

WGA.Logger("test").setLevel("debug")

If your debugging session ist finished reset the logger by executing

WGA.Logger("test").setLevel("info")

Note: If you prefer console.log()/console.debug() over log.info()/log.debug() you can still use named Loggers:

console.logger = WGA.Logger("test").getLogger();
console.debug("some message");