Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 593
dude Avatar asked Dec 22 '10 07:12

dude


People also ask

What is difference between Java util logging and Log4j?

Java Util Logging performance is significantly affected by the lack of a buffered handler. There is no major difference between Log4j and Logback. Both Log4j and Logback show about 50% of the performance of my special case optimized strawman.

What is Java Util logging?

Logging in simple words refers to the recording of an application activity. Logging is used to store exceptions, information, and warnings as messages that occur during the execution of a program. Logging helps a programmer in the debugging process of a program. Java provides logging facility in the java. util.

Which logging framework is best for Java?

One of the most popular solutions for the Java world is the Apache Log4j 2 framework. Maintained by the Apache Foundation, Log4j 2 is an improvement on the original Log4j, which was the most popular logging framework in Java for many years.


1 Answers

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.

like image 182
darioo Avatar answered Oct 02 '22 15:10

darioo