L.6 User log functionality sample program
The userlog is provided as a sample program for confirming the operations of the user log functionality. The following table describes the files provided as samples of the source file and definition files used to execute this sample program:
File name |
Usage |
---|---|
UserLogServlet.java |
Servlet program of user log |
UserLogHome.java |
Home interface |
UserLog.java |
Remote interface |
AdderEJB.java |
Implementation class of Enterprise Bean for calculating the total of integers. |
sample.properties |
Sample property of logger set in the property. |
MyFormatter.java |
Self-defined class provided as a formatter. |
MyFilter.java |
Self-defined class provided as a filter. |
The files are located in the following location.
Cosminexus-installation-directory\CC\examples\userlog
Following is the overview and the execution procedure of sample program with user log functionality:
- Organization of this subsection
(1) Overview of user log functionality sample program
This sample program can output the following 3 types of logs.
-
Type 1: Sample for outputting messages from servlet
The entered message is output from the servlet side.
-
Type 2: Sample for outputting the entered numbers and total value from AdderEJB
The entered values and total of those values are output to the log file from "AdderEJB (Enterprise Bean)" for calculating the total of the entered integers.
-
Type 3: Sample for outputting exception logs from the servlet
Exception is generated and its details are output to the log file from the servlet.
The following figure shows the flow of process in the sample program:
The log file output differs depending on the logger name and log level selected in the Input window.
-
If you select logger name com.example.userlogger1, the log is output to logfileA regardless of the level you specify.
-
If you select logger name com.example.userlogger1 and specify SEVERE or higher in the log level, the log is output to logfileA and logfileB.
-
If you select logger name com.example.userlogger2, specify INFO or higher in the log level and if MyFilter is not used for filtering, the log is output to logfileC. The output formatter "MyFormatter (self-defined class)" is used.
- Specifications of MyFormatter
-
The output format is as follows:
message: Entered-messageLEVEL: Specified-level
- Specifications of MyFilter
-
Messages marked with "debug:" in the heading are not output to the log.
(2) Execution procedure of user log functionality sample program
The following procedure describes the procedure for executing the sample program.
(a) Setting the J2EE server
(b) Compiling the sample file
Compile the user log samples with the batch file (compile.bat) provided in the sample.
On compiling, "myloglib.jar" file is created. Store this file in any directory to allow access to the JAR file. For details on allowing the access to the file, see 8.7.2 Using container extension library in the uCosminexus Application Server Expansion Guide.
(c) Setting the property information
The property information is set in the set up server. Some contents in usrconf.properties of the set up server are rewritten in the set up file (sample.properties) provided in the sample. For building a system using Management Server, see 8.8 Setting the user log output of J2EE applications in the uCosminexus Application Server Expansion Guide.
The storage location of usrconf.properties and the rewritten portion in usrconf.properties file, when the set up server is "MyServer" are as follows:
-
File location
Cosminexus-installation-directory\CC\server\usrconf\ejb\MyServer\usrconf.properties
-
Rewritten portion in the file:
The following part is rewritten with the contents of sample.property.
: # user-log handler settings #ejbserver.application.userlog.CJLogHandler.<Specify handler-name>.path=user_log #ejbserver.application.userlog.CJLogHandler.<Specify handler-name>.count=2 : # user-log logger settings #ejbserver.application.userlog.Logger.<Specify logger-name>.handlers=<Specify handler-class> #ejbserver.application.userlog.Logger.<Specify logger-name>.useParentHandlers=true :
The contents of sample.properties provided in the sample are as follows:
# user-log handler settings #conf1 settings ejbserver.application.userlog.CJLogHandler.conf1.path=userlog/logFileA ejbserver.application.userlog.CJLogHandler.conf1.level=ALL ejbserver.application.userlog.CJLogHandler.conf1.appname=userlog_app ejbserver.application.userlog.CJLogHandler.conf1.formatter=com.hitachi.software.ejb.application.userlog.CJSimpleFormatter #conf2 settings ejbserver.application.userlog.CJLogHandler.conf2.path=userlog/logFileB ejbserver.application.userlog.CJLogHandler.conf2.level=SEVERE ejbserver.application.userlog.CJLogHandler.conf2.appname=userlog_app #conf3 settings ejbserver.application.userlog.CJLogHandler.conf3.path=userlog/logFileC ejbserver.application.userlog.CJLogHandler.conf3.level=INFO ejbserver.application.userlog.CJLogHandler.conf3.appname=userlog_app # user-log logger settings #logger1 settings ejbserver.application.userlog.Logger.com.example.userlogger1.handlers=com.hitachi.software.ejb.application.userlog.CJMessageFileHandler;conf1,com.hitachi.software.ejb.application.userlog.CJMessageFileHandler;conf2 ejbserver.application.userlog.Logger.com.example.userlogger1.level=ALL #logger2 settings ejbserver.application.userlog.Logger.com.example.userlogger2.handlers=com.hitachi.software.ejb.application.userlog.CJMessageFileHandler;conf3 ejbserver.application.userlog.Logger.com.example.userlogger2.level=INFO ejbserver.application.userlog.loggers=com.example.userlogger1, com.example.userlogger2
For the setting of NIO HTTP server, see Appendix L.1(2) Customizing the J2EE server.
(d) Starting the J2EE server
(e) Deploying the application
See Appendix L.1(5) Importing, setting and starting the application.
(f) Executing the application
Start the browser and specify the following string in the URL:
http://Machine-name :Port-number/ContextRoot/userlog.html
When accessing the NIO HTTP server of the J2EE server directly, specify the URL as follows if using the default port:
http://localhost:8008/userlog/userlog_war/userlog.html
(g) Execution example of userlog
The following example shows the method of executing the userlog. The following figure shows the Select the Execution Sample Type window displayed on executing the application and specifying the URL.
Select the type of sample to be executed and move to each data input form. The following example describes the subsequent operations on the window and method to output the log for each selected type.
When the name of the set up server is "MyServer", the resulting log file is output to the following directory by the file name set in usrconf.properties.
Cosminexus-installation-directory\CC\server\public\MyServer\logs\user\userlog
-
Type 1: Execution example of the message output
The following example shows the window transition and output of log file when you select Sample for outputting message from the servlet type on the Select the Execution Sample Type window.
After selecting the type, enter the following values in the displayed Input window:
-
Logger name: com.example.userlogger1
-
Message: AAA
-
Message level: SEVERE (fatal)
The following figure shows the Input window when you select Type 1:
Figure L‒36: Input window (Type 1: User log sample program) The following figure shows the Display Input Result window on clicking the send button after input:
Figure L‒37: Display Input Result window (Type 1: User log sample program) In this example, the result is output to logfileA and logfileB.
The output result of logfileA is as follows:
0310 2005/01/21 20:37:53.296 userlog_app 00922804 01000BCF Msg_100 2005/01/21 20:37:53|UserLogServlet|doPost|fatal|AAA
The output result of logfileB is as follows:
0888 2005/01/21 19:41:03.609 userlog_app 00922804 009B6220 Msg_100 AAA
-
-
Type 2: Execution example of the output of entered numbers and total value
The following example shows the window transition and output of log file when you select Sample for outputting the entered numbers and total value from AdderEJB type on the Select the Execution Sample Type window.
After selecting the type, enter the following values in the displayed Input window:
-
Logger name: com.example.userlogger1
-
Input number: 10
The following figure shows the Input window when you select Type 2:
Figure L‒38: Input window (Type 2: User log sample program) The following figure shows the Display Input Result window on clicking the send button after input:
Figure L‒39: Display Input Result window (Type 2: User log sample program) In this example, the result is output only to logfileA.
The output result of logfileA is as follows:
0324 2005/01/21 20:38:59.500 userlog_app 00922804 015C998A Adder_200 2005/01/21 20:38:59|AdderEJB|add|information|inputNumber = 10 0327 2005/01/21 20:38:59.500 userlog_app 00922804 015C998A Adder_201 2005/01/21 20:38:59|AdderEJB|getTotal|information|total = 10
-
-
Type 3:Execution example of exception logs output
The following example shows the window transition and output of log file when you select Sample for outputting exception logs from the servlet type on the Select the Execution Sample Type window.
After selecting the type, enter the following value in the displayed Input window:
-
Logger name: com.example.userlogger2
The following figure shows the Input window when you select Type 3:
Figure L‒40: Input window (Type 3: User log sample program) The following figure shows the Display Input Result window on clicking the send button after input:
Figure L‒41: Display Input Result window (Type 3: User log sample program) In this example, the result is output only to logfileC.
The output result of logfileC is as follows:
1077 2005/01/21 19:55:19.328 userlog_app 00922804 006458A6 Exp_300 message:Exception LEVEL:SEVERE
-