I've been a little annoyed by the logging (using Log4J) in alot of applications that I currently work on. So im trying to find a way to fix it. The rest of this thread is my idea and questions.
I'm a naive grad btw
My main gripe with it is: all logging is usually wrote to a single log file. The type of applications usually are J2EE web apps(internal + external). The apps are the same as most, a fair few users, they log on, do stuff which requires an audit trail, then finish or in some cases: cause an error, exception, uncover a bug...etc.
I've decided to try come up with a better model to use often. Firstly i don't like that all audit logging is done linearly ordered by time, regardless of the user. So we end up with
Sharon did this Sharon did that Rob logged on Jake entered an invalid password Sharon did something else.
We've a few hundred users on different systems so this gets messy real fast. One idea was to log to files dynamically named(by userId), this could be done programmatically in java by setting the loggers file appender to the "USERID.LOG". I think so anyways. What do yous think of this? would this become far too difficult to maintain with all the files being generated? Would log4j bomb on something like this with a couple hundred users? I suppose an alternative would be to keep logging into the one file but then make it a consistent pattern and build a filter applications that would extract details from "Sharon" only and display them....hmm....that might be better.
Secondly, using for instance, Struts. In the action classes we have access to the "user" object in the HttpSession etc, It makes logging an 'event by user' easy. At the lower DAO layers etc, The user id isn't passed about. So in order to log an event coupled with a user id, would it be good practice to have a static LoggerFactory with a static 'logger' variable that i can set a "userid.log" output path to and simply call this when ever i need to get a hold of the logger? Its not application wide right? its would just a singleton object for that particular users request-response combo?.....hmmm...i need to define that more in my head i think. Im getting a little confused about static scope in a webapp which shares many users. Is it the same as an application scope singleton? I want a static variable accessible by any class but the variable is statically unqiue to only a single users scope. Any ideas?
Thirdly, In the event of a serious exception, I want to record the system state in a much more accurate manner than simply looking for a few key variables like userId + a few params. I would like a dump out of objects within the scope of the exception.(serious exceptions only would implement this part). My idea for this would be to generate an Exception Code, dump the state of the objects into a file named by the exception code and then log the exception code coupled with the userID in a "theseExceptionsHappened.log". Obviously i would also log a note in the usual audit logs too with the exception code. I would like to log the objects state in XML so i can rebuild them into mock objects in a few seconds using a parse like XStream. This would be very helpful in some situations and would allow me to recreate the problem easily and exactly. It would also allow testing of the solution in a better way. Can anyone see a problem with this approach? Would the performance hit be negliable in your opinion? Any other opinions or advice on this? Suggestions for implementations? Holes in my thinking?
Post by:Paul Sturrock
"not on the net"
Welcome to JavaRanch!
Could you please update your display name so it complies with our Naming Policy. You can do this here.
This thread has been viewed 794 times.
All times above are in ranch (not your local) time.
The current ranch time is Sep 21, 2018 17:45:21.