The log object

The log variable is always available to your JavaScript code. It is actually a Java Log4j 2.x Logger object, which has a lot of methods, but the most common are:

  • void trace(String) : output a log message at the Trace level

  • void debug(String) : output a log message at the Debug level

  • void info(String) : output a log message at the Info level

  • void warn(String) : output a log message at the Warning level

  • void error(String) : output a log message at the Error level

  • void fatal(String) : output a log message at the Fatal level

  • boolean isTraceEnabled() : returns true if this logger is logging at the Trace level

  • boolean isDebugEnabled() : returns true if this logger is logging at the Debug level

  • boolean isInfoEnabled() : returns true if this logger is logging at the Info level

  • boolean isWarnEnabled() : returns true if this logger is logging at the Warning level

  • boolean isErrorEnabled() : returns true if this logger is logging at the Error level

The log variable is normally set to the Logger named galliumdata.uselog, which can be configured using the usual log4j mechanisms.

A specific logger is always set to a logging level, which can be:

  • fatal : highest - only fatal messages will be logged

  • error

  • warn

  • info

  • debug

  • trace : lowest - all messages will be logged

Any logging activity that is below the current level will not actually be logged. If performance is not a consideration, you can simply use the level you deem appropriate and let the logger do its job:

log.debug("Now processing packet of type " + packetType + " with data " + data);

If the logger is set to a higher level of logging (like Info), this message will not actually be logged, which means that the building of the string was in vain. This is usually not a major concern, but it can really add up in cases where the code will get executed a lot, like filters for data rows. In these cases, you may save a noticeable amount of CPU by making the logging conditional:

if (log.isDebugEnabled()) {
log.debug("Now processing packet of type " + packetType + " with data " + data);
}