Tim Burns' Personal Weblog Flavored with Math, Java, and Oracle
 
Wednesday, May 5, 2004 [*]
 

Tracking Errors with JavaMail

Most web programmers use a logging framework and handle unexpected errors by reporting them through a static reporting object and forwarding the user to an error page.

My code for reporting an unexpected exception looks something like this:

       public static synchronized void report(Throwable e) {
            ByteArrayOutputStream logResult = new ByteArrayOutputStream();
            e.printStackTrace(new PrintStream(logResult));
            logger.error(logResult.toString());
       }
    
The logger object is an instance of Category in Log4J

Logging helps me identify problems by examining the logs for errors and figuring out what is happening. The problem this method is that I don't examine the logs until someone reports a problem. It would be really nice to figure out that I have an error before most of my users do. The best way I've found to do is to email the error log to myself using Java Mail API.

I like to send email errors only to myself, because I always find problems that aren't really problems at all (eg: user closed their browser during a request). I've found that sending error emails out to people who aren't used to checking code gets me a gaggle of chicken little helpers in my office that keep me from actually figuring out if the latest exception was a real problem or not.

Another nice trick I like to do is add the machine name in the mail subject. I use the command, "InetAddress.getLocalHost().getHostName()," to get the local host and set up a filter that separates my dev, test and production instances. On a production instance if something goes seriously wrong, then if I'm at my desk, I will learn about the problem before my users and can address it before the any chicken little is any the wiser.

 
Comments [0]
 
xml

Personal Favorites

Discovering My Own Backyard

At Least Databases Don't Fly Away

Southwestern Baby Shower Menu

Morning of the Wolf

Autumn lingers in New England

Foraging and Shopping

 

Professional Favorites

Calculating a Moving Average In Oracle
The SVD, Benchmarking and Optimization
The Problem with Software Engineers
Fun with Optimization
Anything new under the sun?
Really Simple Tomcat, Really
J2EE with Free Software
 

The Daily Chronic

Brown News
Carl Zimmer
Dijkstra
Dive into Mark
Get Fuzzy
Instapundit
John Udell
Kevin Drum
Late Night Hacking
Lorrianne Schaub
Mark Rittman
Mike Shoemaker
Philip Greenspun
Photo Matt
Salon
Science Blog
Signal+Noise
Woods Hole News
 

References

BioInformatics

BioTech

Epicurious

Statistics

 

Archive

2004
 May 05 06 10
 April 01 04 07 09 11 16 17 18 20 22 24 25 27 29
 March 02 15 21 22 24 27
 February 13
 January 04 16 19 29
2003
 December 06 12
 November 02 23 29
 October 07 11 12 16 18 21 24 26
 September 04 09 10 12 14 28
 August 05 08 13 17 18 25 29
 July
 June
2002
2001
 

Photos

Morning of the Wolf
Phantom Farms
Providence
Baby Shower
Camden, Maine
 

Wiki

Creative Commons License
This work is licensed under a Creative Commons License