What is the difference between log4j and java.util.logging
Which is b开发者_如何学Cest for getting the log files of user logged in his account? Explain with a small example... Thanks for your time...
Log4j is a defacto standard logging library for Java.
Java.util.logging is a built in logging mechanism in Java, but that doesn't make it the greatest...
Use Log4j and its MDC. This way, you can easily log different user accounts like this:
MDC.put(user);
logger.log("Deleted something important!");
This way, if logging is configured correctly, in your log output you will see something like this:
[user Alice] Deleted something important!
and this will work for every user in a multi user environment.
Note: if you're starting a new project, I'd suggest using slf4j and Logback. This combination is even more powerful than log4j or java.util.logging.
I have been using this combination for some time and it has really paid off handsomely. Very useful for bug squashing and auditing user interaction, among other things.
精彩评论