dude
dude

Reputation: 4982

What is the difference between log4j and java.util.logging

Which is best for getting the log files of user logged in his account? Explain with a small example... Thanks for your time...

Upvotes: 6

Views: 3993

Answers (1)

darioo
darioo

Reputation: 47213

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.

Upvotes: 6

Related Questions