Adding Logging to Your Scripts

You can add logging to scripts.

The dw.system.Logger class includes the following methods:

  • getRootLogger() : Log - A static method for retrieving a category logger.
  • getLogger( String category ) : Log - A method for logging to this category logger. A category name must only consist of alpha numeric characters and a ".".

The dw.system.Log class lets you write to a specific log level and category. This class has the following methods:

  • public void debug( String msg, Object... args );
  • public boolean isDebugEnabled();
  • ... similar methods for info, warn, and error
  • public void fatal( ... );

For NDC support, the static method LogNDC getNDC() provides access to the NDC. The NDC property supports access to the nested diagnostic context.

The following methods are instance methods and not class methods:

  • debug( String msg, Object... args ) : void
  • isDebugEnabled() : boolean
  • info( String msg, Object... args ) : void
  • isInfoEnabled() : boolean
  • warn( String msg, Object... args ) : void
  • isWarnEnabled() : boolean
  • error( String msg, Object... args ) : void
  • isErrorEnabled() : boolean
  • fatal( ... );
Note: Fatal is always enabled.

The API class dw.system.LogNDC has the following methods.

Method Description
push( String message ) : void Pushes new diagnostic context information for the current script execution.
peek() : String Looks at the last diagnostic context at the top of this NDC without removing it. The returned value is the value that was pushed last. If no context is available, then the empty string "" is returned.
pop() : String Call this method before leaving a diagnostic context. The returned value is the value that was pushed last. If no context is available, then the empty string "" is returned.
remove() : void Removes the diagnostic context for this script call.