Shashank Kadne
Shashank Kadne

Reputation: 8101

Difference between Logger.getLogger(className) and LogFactory.getLog(className )?

I know its a package difference

1) org.apache.log4j.Logger logger = Logger.getLogger(clazz);

2) org.apache.commons.logging.Log log = LogFactory.getLog(clazz);

The first one uses loggers via log4j and the second one uses commons.logging. We have a huge project where in some classes loggers are configured using log4j and in some cases its commons.logging.

I did find a log4j property file though.Is there a similar property file for commons.logging ? Where do I configure for commons-logging ?. I am unable to see the logs generated by commons-logging.

Any help is appreciated.

Upvotes: 21

Views: 26383

Answers (1)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340743

Yes, commons-logging is a facade API that was suppose to abstract you from underlying logging framework (in practice there was a choice between and java.util.logging) so that you could switch from one to another without touching the code - just by switching libraries available on the CLASSPATH.

Unfortunately due to some design mistakes it had issues with complex class-loading environments, like application servers. Currently it is effectively superseded by .

In your case I would recommend sticking with one API - either Log4J or commons-logging, even though commons-logging will (most likely) delegate to log4J. You can also migrate to using SLF4J and install bridging APIs, but this is slightly more advanced.

Upvotes: 12

Related Questions