intra-mart Accel Platform / Script Development Model Programming Guide

«  Database   ::   Contents   ::   UI (Design Guidelines)  »

Log

Overview

Log is output with the intention of internal control, to ensure the security and maintenance, etc.
In this item log implementation carried out by Script Development Model is mentioned.

To use Logger API

Log level

5 log levels are provided in Logger API.
trace (Most insignificant)
debug
info
warn
error (Most Significant)

To Acquire Logger Object

function add(value1, value2) {
    // Acquires logger object
    // File name becomes the logger name since the logger name is not specified
    // File location : <CONTEXT_PATH>/WEB-INF/jssp/src/foo/bar/logger_sample.js
    // Logger Name : 'foo.bar.logger_sample'
    var logger = Logger.getLogger();
}
Acquire Logger object by using Logger.getLoggermethod(). String passed to argument becomes the logger name.
When nothing is passed to the argument, this method is created on the basis of the source path of the called JS file. Basically, the string replaced by the ”.” for the file separator of the source path of the JS file is considered as the logger name. In addition, source path of JS file indicates the relative path (Without extension) from source search directory.

To Output The Log

function add(value1, value2) {
    // Acquires logger object
    // File name becomes the logger name since the logger name is not specified
    // File location : <CONTEXT_PATH>/WEB-INF/jssp/src/foo/bar/logger_sample.js
    // Logger Name : 'foo.bar.logger_sample'
    var logger = Logger.getLogger();

    logger.debug('arguments=[{}, {}]', value1, value2);
    var result = value1 + value2;
    logger.trace('result={}', result);

    return result;
}
Output the log by using Logger object.
In the above mentioned function, the value passed to the argument is output at debug level and the calculation result is output at trace level.
When add(1, 2) is executed at log level debug, the output is as follows.
[DEBUG] f.b.logger_sample - arguments=[1, 2]
When add(1, 2) is executed at log level trace, the output is as follows.
[DEBUG] f.b.logger_sample - arguments=[1, 2]
[TRACE] f.b.logger_sample - result=3

To Use LoggerMDC API

MDC

The information stored in a key which is uniquely defined in layout settings of log configuration file can be output in log by using Mapped Diagnostic Context.
The information of the key which is uniquely defined can be written by using LoggerMDC API.

To output log where MDC has been used

// Defines MDC key
var MDC_FUNC_KEY = 'application.func';
function add(value1, value2) {
    // Acquires logger object
    // File name becomes the logger name since the logger name is not specified
    // File location : <CONTEXT_PATH>/WEB-INF/jssp/src/foo/bar/logger_sample.js
    // Logger name : 'foo.bar.logger_sample'
    var logger = Logger.getLogger();

    // Sets value in MDC
    LoggerMDC.put(MDC_FUNC_KEY, 'add');

    logger.debug('arguments=[{}, {}]', value1, value2);
    var result = value1 + value2;
    logger.trace('result={}', result);

    // Initializes value of MDC
    LoggerMDC.remove(MDC_FUNC_KEY);

    return result;
}
The function identifier which is being executed is set in MDC.
The “add” function identifier that is being executed is set in MDC key “application.func” by LoggerMDC.put(key, value) method.
The value of the contents stored in MDC will not be initialized unless it is explicitly done.
Therefore, after the completion of intended log output process, the value of MDC key “application.func” is initialized by LoggerMDC.remove(key) method.
Output Example
Change the contents of <configuration>/<appender name=”STDOUT”>/<encoder>/<pattern> of <CONTEXT_PATH>/WEB-INF/conf/log/im_logger.xml as below and restart the application server.
[%level] %logger{10} - %X{application.func} %msg%n
Log output when add(1, 2) is executed at log level trace
[DEBUG] f.b.logger_sample - add arguments=[1, 2]
[TRACE] f.b.logger_sample - add result=3

«  Database   ::   Contents   ::   UI (Design Guidelines)  »