Hitachi

uCosminexus Application Server Expansion Guide


8.8.3 Examples of the user log output of applications

This section describes the settings used to output the user log of J2EE applications, with specific examples.

Organization of this subsection

(1) Example used for user log output

This subsection describes the settings used to output the user log of J2EE applications, with the following example. The following figure gives an overview of the used example.

Figure 8‒4: Example of user log output of J2EE applications

[Figure]

In company A, the operation history of J2EE applications is output to the log file as a business history, by using the logger functionality. Among the J2EE applications of Company A, the J2EE applications, for which operation history is to be output, are of two types; Application1 and Application2. For each J2EE application, logs of different message levels are output to different files. The directories of J2EE application names are created and stored in respective log files, in the above figure.

(a) Features of "Application1"

com.example.userlogger1 is the logger name of Application1.

Application1 is a complex and large J2EE application. If a critical error of the SEVERE level occurs, a message containing the trace information of Java Exception is retained in logfileA, to quickly identify the cause. The messages of the INFO level and below are output to logfileB as the trace log of operations. To output two types of log files from com.example.userlogger1, depending on the output level and the output contents of the log, two types of CJMessageFileHandler handlers (conf1 and conf2) are created.

Details of "logfileA"
  • To acquire the trace information, you use "CJSimpleFormatter" as an output formatter to logfileA.

  • Only SEVERE level messages are output to logfileA, so a log file of a very large size is not required. However, as the trace information is output, a size of approximately 40 megabytes is required to accumulate 10,000 records, with a maximum size of records per message as 4,096 bytes. Therefore, set the file size to 10 megabytes and number of files to 4.

  • Set the name of the J2EE application to "my_app1" for distinguishing the messages output by Application1.

Details of "logfileB"
  • All the messages of the INFO level and below are output, so logfileB requires a larger file size. The log disc capacity, calculated from the amount of messages per day and the retention period, is approximately 256 megabytes. The maximum number of files is 16, therefore set the file size to 16 megabytes and number of files to 16.

  • Set the name of the J2EE application to "my_app1" for distinguishing the messages output by Application1.

(b) Features of "Application2"

com.example.userlogger2 is the logger name of Application2.

Application2 is built with high quality log messages and is a small J2EE application. Only the necessary minimum messages are output to logs, so the messages of WARNING and above level are retained in "logfileC". One log file is output from com.example.userlogger2, so the CJMessageFileHandler handler, which is called conf3, is created.

Details of "logfileC"
  • Only the WARNING level messages are output. The maximum length per message is approximately 200 bytes, approximately 2 megabytes size is required for accumulating 10,000 records. As a result, you set the file size to 1 megabyte and number of files to 2.

  • You set the name of the J2EE application to "my_app2" for distinguishing the messages output by Application2.

(c) Settings for debugging

You also specify the settings for debugging during development. For displaying all the message contents that are sent to "com.example.userlogger1" and "com.example.userlogger2", you connect "ConsoleHandler" of the java.util.logging to "com.example" logger. Because all the message contents propagated from a child logger are to be displayed in this logger, you set the log acquisition level of the logger and the handler to ALL.

(2) Example of setting the user log output

The following example shows the settings for the user log output, with the example shown in (1) Example used for user log output.

(a) Example of setting the Easy Setup definition file

The following example describes the settings of the Easy Setup definition file (when defining physical tier):

<configuration>
  <logical-server-type>j2ee-server</logical-server-type>
<!-- Perform settings so that you cannot propagate the log record passed -->
<!-- to logger, to handler used by parent logger (because root logger -->
<!-- exists by default). -->
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.useParentHandlers</param-name>
    <param-value>false</param-value>
  </param>
<!-- Specify J2EE application name, output destination, size, -->
<!-- number of files, log acquisition level -->
<!-- and formatter name to be used of "logfileA". -->
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf1.appname</param-name>
    <param-value>my_app1</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf1.path</param-name>
    <param-value>application1/logfileA</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf1.limit</param-name>
    <param-value>10485760</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf1.count</param-name>
    <param-value>4</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf1.level</param-name>
    <param-value>SEVERE</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf1.formatter</param-name>
    <param-value>com.hitachi.software.ejb.application.userlog.CJSimpleFormatter</param-value>
  </param>
 
<!-- Specify J2EE application name, output destination, size, -->
<!-- number of files, log acquisition level of "logfileB" -->
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf2.appname</param-name>
    <param-value>my_app1</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf2.path</param-name>
    <param-value>application1/logfileB</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf2.limit</param-name>
    <param-value>16777216</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf2.count</param-name>
    <param-value>16</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf2.level</param-name>
    <param-value>INFO</param-value>
  </param>
 
<!-- By using settings of "conf1" and "conf2" handler names, used by-->
<!-- "com.example.userlogger1",-->
<!-- initialize and connect the file handler (CJMessageFileHandler). -->
<!-- Here, logger and handler is created. -->
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.userlogger1.handlers</param-name>
    <param-value>com.hitachi.software.ejb.application.userlog.CJMessageFileHandler;conf1,
                  com.hitachi.software.ejb.application.userlog.CJMessageFileHandler;conf2</param-value>
  </param>
 
<!-- Specify log acquisition level of "com.example.userlogger1". -->
<!-- Match it with higher level of "conf1" and "conf2", and set to "INFO". -->
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.userlogger1.level</param-name>
    <param-value>INFO</param-value>
  </param>
 
<!-- Specify output destination and log acquisition level of "logfileC". -->
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf3.appname</param-name>
    <param-value>my_app2</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf3.path</param-name>
    <param-value>application2/logfileC</param-value>
  </param>
  <param>
    <param-name>ejbserver.application.userlog.CJLogHandler.conf3.level</param-name>
    <param-value>WARNING</param-value>
  </param>
 
<!-- By using settings of "conf3" handler name, used by -->
<!-- "com.example.userlogger2",-->
<!-- initialize and connect the file handler (CJMessageFileHandler). -->
<!-- Here, logger and handler are created. -->
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.userlogger2.handlers</param-name>
    <param-value>com.hitachi.software.ejb.application.userlog.CJMessageFileHandler;conf3</param-value>
  </param>
 
<!-- Specify log acquisition level of "com.example.userlogger2". -->
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.userlogger2.level</param-name>
    <param-value>WARNING</param-value>
  </param>
 
<!-- Perform settings for -->
<!-- debugging************************************************-->
<!-- Specify log acquisition level of "ConsoleHandler". -->
  <param>
    <param-name>java.util.logging.ConsoleHandler.level</param-name>
    <param-value>INFO</param-value>
  </param>
 
<!-- Specify "ConsoleHandler" handler name to be used in "com.example" logger,-->
<!-- and connect to handler. Here, logger and handler are created. -->
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.handlers</param-name>
    <param-value>java.util.logging.ConsoleHandler</param-value>
  </param>
 
<!-- Specify log acquisition level of "com.example" logger. -->
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.level</param-name>
    <param-value>ALL</param-value>
  </param>
 
<!-- If debugging is not required, cancel the setting of propagation to -->
<!--parent logger. -->
<!--
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.userlogger1.useParentHandlers</param-name>
    <param-value>false</param-value>
  </param>
-->
<!--
  <param>
    <param-name>ejbserver.application.userlog.Logger.com.example.userlogger2.useParentHandlers</param-name>
    <param-value>false</param-value>
  </param>
-->
<!-- If debugging is not required, cancel the creation of "com.example". -->
<!--
  <param>
    <param-name>ejbserver.application.userlog.loggers</param-name>
    <param-value>com.example.userlogger1, com.example.userlogger2</param-value>
  </param>
-->
<!-- *************************************************************************-->
 
<!-- Declare the usage of logger. -->
  <param>
    <param-name>ejbserver.application.userlog.loggers</param-name>
    <param-value>com.example,com.example.userlogger1,com.example.userlogger2</param-value>
  </param>
</configuration>

(b) Example of setting Application1

The following example describes the source code of Application1:

import java.util.logging.*;
import com.hitachi.software.ejb.application.userlog.*;
 
public class application1{
 
    static Logger logger = Logger.getLogger("com.example.userlogger1");
 
    public static void exec(){
 
        logger.log(
                   CJLogRecord.create(Level.INFO,
                   "application1 start.","AP1_10000-I"));
 
        try{
 
            throw new Exception("Exception1!");
 
        }
        catch(Exception ex){
 
            logger.log(
                       CJLogRecord.create(Level.SEVERE,
                       "Catch an exception!", ex, "AP1_10100-E"));
 
        }
 
        logger.log(
                   CJLogRecord.create(Level.INFO,
                   "application1 end.","AP1_10001-I"));
 
    }
 
}

The following example describes the output of application1/logfileA1.log:

     yyyy/mm/dd hh:mm:ss.sss            pid      tid      message-id  message(LANG=ja)
0047 2003/12/06 19:51:32.265  my_app1   00EB7859 012A54F9 AP1_10100-E 2003/12/06 
19:51:32|application1|exec|Fatal|Catch an exception!|java.lang.Exception: 
Exception1!|application1.exec(application1.java.18)|application1.main(application1.java.64)

The following example describes of the output of application1/logfileB1.log:

     yyyy/mm/dd hh:mm:ss.sss           pid      tid      message-id   message(LANG=ja)
0046 2003/12/06 19:51:32.250  my_app1  00EB7859 012A54F9 AP1_10000-I  application1 start.
0048 2003/12/06 19:51:32.265  my_app1  00EB7859 012A54F9 AP1_10100-E  Catch an exception!
0049 2003/12/06 19:51:32.265  my_app1  00EB7859 012A54F9 AP1_10001-I  application1 end.

The following example describes the output to the console screen:

Information: application1 start.
2003/12/06 19:51:32 application1 exec
Fatal: Catch an exception!
java.lang.Exception: Exception1!
        at application1.exec(application1.java:18)
        at application1.main(application1.java:64)
2003/12/06 19:51:32 application1 exec
Information: application1 end.

(c) Example of setting Application2

The following example describes the source code of Application2:

import java.util.logging.*;
import com.hitachi.software.ejb.application.userlog.*;
 
public class application2{
 
    static Logger logger = Logger.getLogger("com.example.userlogger2");
 
    public static void exec(){
 
        logger.log(
                   CJLogRecord.create(Level.INFO,
                   "application2 start.","AP2_20000-I"));
 
        try{
 
            throw new Exception("Exception2!");
 
        }
        catch(Exception ex){
 
            logger.log(
                        CJLogRecord.create(Level.SEVERE,
                       "Catch an exception!", ex, "AP2_20100-E"));
 
        }
 
        logger.log(
                   CJLogRecord.create(Level.INFO,
                   "application2 end.","AP2_20001-I"));
 
    }
 
}

The following example describes the output of application2/logfileC1.log:

     yyyy/mm/dd hh:mm:ss.sss           pid      tid      message-id   message(LANG=ja)
0048 2003/12/06 19:51:32.265  my_app2  00EB7859 012A54F9 AP2_20100-E  Catch an exception!

(d) Example of setting Application3

This subsection describes an example of the log output of the J2EE application Application3, to the same log file as of Application1. In such cases, Application3 must acquire the logger by using the same logger name in the same process (thread may be different) as Application1.

The following example describes the source code of Application3:

import java.util.logging.*;
import com.hitachi.software.ejb.application.userlog.*;
 
public class application1{
 
    static Logger logger = Logger.getLogger("com.example.userlogger1");
 
    public static void exec(){
 
        logger.log(,
                   CJLogRecord.create(Level.INFO,
                   "application3 start.","my_app3","AP3_30000-I"));
 
        try{
 
            throw new Exception("Exception2!");
 
        }
        catch(Exception ex){
 
            logger.log(,
                       CJLogRecord.create(Level.SEVERE,
                       "Catch an exception!", ex, "my_app3","AP3_30100-E"));
 
        }
 
        logger.log(
                   CJLogRecord.create(Level.INFO,
                   "application3 end.","my_app3","AP3_30001-I"));
 
    }
 
}

The following example describes the output of application1/logfileB1.log:

     yyyy/mm/dd hh:mm:ss.sss           pid      tid      message-id   message(LANG=ja)
0046 2003/12/06 19:51:32.250  my_app1  00EB7859 012A54F9 AP1_10000-I  application1 start.
0093 2003/12/06 19:51:32.265  my_app3  00EB7859 010CB027 AP3_30000-I  application3 start.
0095 2003/12/06 19:51:32.265  my_app1  00EB7859 012A54F9 AP1_10100-E  Catch an exception!