Difference in using java.util.logging and Log4j Loggers

I am developing a Java application for which I have to use the logging mechanism. And now I'm confused to choose a java library registrar or go for the Log4j logger.

So, I want to know when I can go for java logger and when I can go for log4j logger.

+7
java logging log4j java.util.logging
source share
5 answers

I suggest you switch to SLF4J to separate your application from certain logging frameworks. It has adapters for various popular logging frameworks such as Jakarta Logging, JDK1.4 logging, log4j, etc., which makes it a good abstraction for logging.

+10
source share

The Logger class was not part of jdk before, so several library implementations have appeared. The Log4j library has one of the most comprehensive sets of logging utilities (Formatters, Appenders, etc.). However, for most developers this would be superfluous, and a simple java.util.Logger would be enough.

I personally use a custom shell to implement my registrar. This allows me to define custom calls to perform functional logging / auditing.

+3
source share

There is the Apache Commoms Logging Project and SLF4J , each of which abstracts the main logging library.

In practice, I usually use Log4J over the built-in logging classes. Mostly because Log4J can be configured for each web application on the application server, while the JDK log is configured for the JVM.

+3
source share

I currently recommend using SLF4J as the logging API. Then you can choose the logging structure depending on your needs when you discover them.

I recorded what I consider best practice when starting out with SLF4J and the simple "log to System.out" that is currently hosted. http://runjva.appspot.com/logging101/index.html

Hope this helps.

+3
source share

I find Log4j more flexible when it comes to setting up cfg logging without recompiling code in a production environment.

+2
source share

All Articles