views:

68

answers:

4

I need to set up a logging system for my java web application that not only logs the usual stuff (error message, error level, etc) but can also log additional information as well such as session ID. Sure I suppose I could put the session ID in the error message, but the problem is that I will end up logging lots and lots of data for lots of different users and I need to end up having a system where I can look at the log and sort the log based on session ID.

I've been looking at log4j coupled with chainsaw, and I think I could extend log4j to add additional attributes which is great, but then how do I view those custom attributes in chainsaw?

Surely i'm not the first one to have had this problem, is there something else I could use besides log4j coupled with chainsaw?

A: 

I don't know chainsaw, but logging additional cross-cutting information such as session ids, user names, requesting ip, ... is usually done through the nested diagnostic context.

meriton
Okay, how do I create or get an NDC? I assume i'm supposed to use LoggingEvent.getNDC(), but how do I then get a logging event? All I have is a logger, an appender, and a layout object.
Ring
Read the javadoc I linked. Note that the operations to manipulate an NDC are static, you don't need to get an instance of class NDC to use the NDC. Also note that a PatternLayout can be configured to print the current content of the NDC.
meriton
Ahh haha. Thank you, silly me, for some reason my mind was blocked and kept thinking those were instance methods.
Ring
A: 

Are you logging or auditing your users?

Auditing involves reviewing user actions as a part of normal operations and belongs in a database.

Logging is more for break/fix.

Freiheit
A: 

Best thing to do would be to insert that data into a database. That way you can have indexes on session id and quickly retrieve and sort all the information either using straight SQL, or creating a light weight webapp for viewing the data from the database given a session id or other criteria to search on.

If you want a quick solution that you can feed existing log files into - try out splunk

HTH

simonlord
A: 

Disclaimer: I'm one of Chainsaw's committers...

Chainsaw will display the NDC value in its own column, and will display any MDC entries as their own column as well.

Lots of new features coming in the upcoming release (soon) which make it easy to filter, colorize, search and sort..or, pull Chainsaw + the log4j companions down via svn and build with maven...

One really handy feature: the ability to add comments to individual events, save off the events from inside Chainsaw and email the resulting file to others, who can see your comments in the table.

Here's a screen video: http://people.apache.org/~sdeboy/chainsawdemo.avi

Scott