Tutorial :Logging And Easily Viewing Large Amounts Of Session Data In Java


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?


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.


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


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.


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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »