Download presentation
Presentation is loading. Please wait.
Published byNathan Phelps Modified over 9 years ago
1
® IBM Software Group © 2006 IBM Corporation How to utilize logging in EGL 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.
2
2 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 target’s 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.
3
3 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 ExternalType’s Log4j allows you to specify many different properties for your entire project through a single configuration file.
4
4 Log4j We’ll 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 Copy/Paste the code in the notes into the file There are two config files in the notes of this slide The first config file tells log4j to write to a file The second config file, which is commented out, allows log4j to write to the console Note that the default log level is set to Error, this means that only log’s of greater severity will be written out. This gives you greater control over all of your log’s, and the ability to optimize for speed by only turning on certain logging levels when needed.
5
5 Log4j Now let’s 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 Make sure to try the second config file as well Sample Output
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.