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

What is the best way to get user log files registered in his account? Explain with a small example ... Thanks for your time ...

+6
java log4j java.util.logging
source share
1 answer

Log4j is the standard defacto logging library for Java.

Java.util.logging is the built-in logging mechanism in Java, but that does not make it the biggest ...

Use Log4j and its MDC . Thus, you can easily register various user accounts as follows:

MDC.put(user); logger.log("Deleted something important!"); 

Thus, if logging is configured correctly, you will see something like this in the log output:

[user Alice] Deleted something important!

and this will work for each user in a multi-user environment.

Note: if you are starting a new project, I would suggest using slf4j and Logback . This combination is even more powerful than log4j or java.util.logging.

I used this combination for some time, and it really paid off beautifully. Very useful for noise reduction and auditing user interactions, among other things.

+6
source share

All Articles