8.2.2 Mechanism of the user log output
You can use the Java logging APIs of J2SE for executing J2EE applications, batch applications, and EJB client applications to output user logs. A Java logging API is a highly versatile API that can output multiple items such as memories, consoles, and files. However, the logic is simple, so for applying the logic to a mission critical system, an application developer must implement reliable and durable classes for log output.
If you use the user log functionality, a highly reliable user log can be output, even if the classes for the log output are not implemented by the application developer.
You can output logs, which are output from J2EE applications, batch applications, and EJB client applications developed by using the Java logging APIs, in a format output by a component software of another Cosminexus system (Hitachi Trace Common Library format) by using Hitachi Trace Common Library. By using this library you can handle user logs in the same format as the other system logs, and the log operation can be highly reliable and unified.
You execute the user log output in accordance with the mechanism of the J2SE Java logging. With the Java logging, you use two types of elements, loggers and handlers. Note that loggers and handlers are the objects of the Logger class and the Handler class respectively.
The following figure shows the mechanism of Java logging.
The following points describe the above figure:
-
Output user logs from applications by using logger.
The user logs are output by using the methods of the Logger class, when the application is processing.
-
Logger adds additional information such as levels and message strings to the log, which is output from the application, converts to LogRecord, and passes to the handler.
At that time, you can have fine control above the control specified as a log level, by using the filter (object of the Filter class) that is connected to the logger.
-
Based on the received LogRecord, the handler outputs logs to a file, console or a socket.
You specify the output destination and the output format as a handler property, in advance. In handler, you can have fine control by using the filter connected to the handler. You can also use the formatter (object of the Formatter class) to output messages formatted in any format.
With Application Server, the file handlers are provided to output logs in the Hitachi Trace Common Library format, in a file. The following sub-sections describe the provided file handlers for respective applications.
-
For J2EE applications or batch applications
CJMessageFileHandler is provided as a file handler. You can specify the log output destination files, log levels, number of log files, and filters and formatters to be used for CJMessageFileHandler, when setting up a system. For details on setting the user log output of J2EE applications and batch applications, see 8.8 Setting the user log output of J2EE applications and 8.9 Setting the user log output of batch applications.
In a user log, if you want to output the message ID corresponding to the application name and message contents that are output by the log, you must implement the settings in J2EE applications or batch applications. In such cases, implement the settings by using a class for the extended LogRecord provided by Application Server (CJLogRecord class). For details on how to use the CJLogRecord class, see 8.4 Methods used in the user log output. For details on the APIs of the CJLogRecord class, see 7. APIs used in the user log functionality in the uCosminexus Application Server API Reference Guide.
- Important note
-
For directly implementing the settings of handlers and loggers in J2EE applications, you must have the security permission LoggingPermission("control") for the application to be executed. For details on how to specify the security permission LoggingPermission("control"), see 8.8.2 Setting security policy.
-
For EJB client applications
CJMPMessageFileHandler is provided as a file handler. How to set up a user log of an EJB client application varies according to the command used to start the EJB client application. For details on how to set up the user log output for EJB client applications, see 8.10 Setting the user log output of EJB client applications (When using the cjclstartap command) or 8.11 Implementing and setting the user log output of EJB client applications (When using the vbj command).