Call Us Toll Free: (866) 217-9701
Here at Web Inspired we right a lot of java. We are not big fans of php (it scares us from a security standpoint). We substitute jsf for php. We feel jsf is superior because the pages are backed by object oriented java code. We use log4 j to handle our logging.
We like log4j because it is very easy to set up, it's customizable and it just works. You can download log4j from Apache at: http://logging.apache.org/log4j/1.2/download.html. Since we do all our programming in netbeans, this blog post will be written from the netbeans user perspective.
To utilize log4j you will have to include it's jar file in your project. Right click on your project, click properties then click the Libraries button, lastly click the add bar/folder button and find the log4j jar you downloaded. You will have to create a log4j config file in your default package (Source Packages ->), call it log4j.XML. My log4j config file looks like this:
As you can see my config file looks pretty pedestrian and easy to follow. The one thing I would like to point out is the fact that we write 2 log files (look at the appenders). One generic text file and an XML log file. We include a non XML lot file because the times stamp on the XML file is hard to read, some of our developers don't like to use log readders.
You might be asking why we include an XML log file if its so darn hard to read. We love the XML log files for 2 main reasons. The first reason is that we have written a java program that fires from the Linux Cron tab in the wee hours of the morning that emails our developers any errors that where caught the previous day. This tool was written in a couple hours and it might be the most valuable code we have in house. It helps us to catch errors early before they become a huge problem. In an ideal world these errors would be caught during testing, but its not always the case. The second reason we love XML log files is that they can be fed to log readers easily. The code usitilzes jdom and the javamail api. We use logmx (downloadable here) to read our XML log files and we think its fantastic. LogMX looks like this:
This concludes this weeks needy blog post. I hope it was helpful. Check out log4j as well as logmx. As a quick word of advice I would recommend using some sort of logging library for applications big and small. It might take a few minutes but the information they provide is invaluable.
admin in General 10:46PM Sep 06, 2011 Comments[1]
view portfolio