Académique Documents
Professionnel Documents
Culture Documents
This Learning Module shows how to utilize the open source log4j project
from within EGL. Log4j is fully J2EE compatible and customizable by a single
".properties" file.
Log4j
Log4j is an open source project sponsored by the Apache Software
Foundation
It is a logging framework written in Java, which provides you with a method
to keep track of exactly what your application is doing
Log4j utilizes a hierarchical structure allowing you to easily control which log
statements are output, while maximizing performance
This logging structure provides you with several different logging statements of varying
severity (the top of the list is the least severe, while the bottom is the most)
Trace
Debug
Info
Warn
Error
Fatal
With Log4j you are able to output to many targets and control every aspect
of the framework through a simple configuration file.
To use log4j in your EGL project, you will need the log4j jar file, and the
ExternalType in order to access the Java.
2
Log4j
If it is not there already, make sure the log4j-1.2.15.jar file exists within the WEB-INF/lib
directory of your project (Refer to the RPG workshop if you need further instruction on how
to do this)
Right-Click over EGL Source and create a new EGL Source File called
log4jComponent.egl in the package log4j.
Replace the boiler plate code with the code from the notes
Note that there is only two ExternalTypes
Log4j allows you to specify many different properties for your entire project through a single
configuration file.
3
Log4j
Well now create the configuration file to control the log4j framework
Right-click over \Java Resources:src\
Select: New > Other General File
Name the file: log4j.properties
Log4j
Now lets create a program to test log4j
Right-click over the programs package
and create a new program called
testLog4j
Your log4j set up should be working
with your first config file, which sets the
root level to Error and writes out to a
file
Add a break point in the program
Right-Click over the file name and
debug
Note the output in the
myapplication.log file created
within the root level of your
workspace
Now uncomment the second line of
code, which overrides the config file
and sets the level to ALLLEVELS
Debug again, note the output now
Sample Output