Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in using java.util.logging and Log4j Loggers

I am developing a java application for which i have to use a logging mechanism. And now i am confused to choose either java libraries logger or to go for Log4j logger.

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

like image 840
GuruKulki Avatar asked Feb 13 '10 10:02

GuruKulki


3 Answers

I'd suggest you go with SLF4J instead to decouple your application from specific logging frameworks. It has adapters for various popular logging frameworks such as Jakarta Logging, JDK1.4 logging, log4j etc. making it a good abstraction for logging needs.

like image 110
Esko Avatar answered Sep 27 '22 21:09

Esko


Logger class was not part of jdk earlier on, so several library implementations sprung up. The Log4j library has one of the most comprehensive set of logging utilities (Formatters, Appenders etc). However, for most developers this would be an overkill and the simple java.util.Logger would suffice.

I personally use a custom wrapper over my logger implementation. This enables me to define custom calls to carry out functional logging/auditing.

like image 31
questzen Avatar answered Sep 27 '22 21:09

questzen


There are the Apache Commoms Logging project and SLF4J, either of which abstracts the underlying logging library.

In practice I tend to use Log4J over the built in logging classes. Mainly because Log4J can be configured per web-app in an application server, whereas JDK logging is configured per JVM.

like image 32
Nate Avatar answered Sep 27 '22 21:09

Nate