JavaScript global method: getLog

This method retrieves a logger named according to the value of the name parameter.

Syntax

getLog (name)

Arguments

The following argument is valid for this function.

Argument Data type Required Description
name String Yes The name of the logger to retrieve

Return values

A logger named according to the value of the name parameter.

Description

This method retrieves a logger named according to the value of the name parameter. Loggers are normally named entities, using dot-separated names such as "lib.test01.func01." The logger object in JavaScript is an adapter of log4j in the Service Manager server. Logger names and levels follow the rules of log4j.

Example

This example does the following:

  1. Retrieve a logger with the given name.
  2. Set the logger level to trace.
  3. Print different level messages.
  4. Set the log levels by the code.
var log = getLog('lib.test01.func01');
log.setLevel('trace');
 
if (log.isTraceEnabled()){
log.trace('trace message');
}
 
if (log.isDebugEnabled()){
log.debug('debug message');
}
 
if (log.isInfoEnabled()){
log.info('informatin message');
}
 
if (log.isWarnEnabled()){
log.warn('warning message');
}
 
if (log.isErrorEnabled()){
log.error('error message');
}
 
if (log.isFatalEnabled()){
log.fatal('fatal message');
}
// Set level by code
log.setLevel("trace");
log.setLevel("debug");
log.setLevel("info");
log.setLevel("warn");
log.setLevel("error");
log.setLevel("fatal");
 
log.setLevel(0); //trace
log.setLevel(1); //debug
log.setLevel(2); // info
log.setLevel(3); // warn
log.setLevel(4); // error
log.setLevel(5); // fatal

 

To set a Javascript logger level, follow these steps:

  1. Go to Tailoring > Script Library.
  2. Click More > Javascript Logger.
  3. In the Name field, type the name of the logger.
  4. In the Level field, select a value from the following values: Trace, Debug, Info, Warn, Error, and Fatal.
  5. Click Save.

Note The logger level will be cleared after the Service Manager server is restarted.