Reputation: 32321
Could anybody please tell me what's the relation between log4j and apache.commons.logging ? which one is more popular and better ?
I have imported an existing Application in which they have imported import org.apache.commons.logging.LogFactory;
and written a separate class called Log
and overridden some of the methods as critical
, warn
, info
For instance
public static void info(String caller, String toWrite)
{
write(caller,toWrite,Log.INFO);
}
Could anybody please tell me is log4j and apache.commons.logging are different ??
Upvotes: 17
Views: 22838
Reputation: 585
As per java-doc documentation of commons-logging
Concrete subclass of LogFactory that implements the following algorithm to dynamically select a logging implementation class to instantiate a wrapper for:
Hence inference is:
JavaDoc URL: https://commons.apache.org/proper/commons-logging/javadocs/api-1.1.3/index.html
Upvotes: 1
Reputation: 1156
log4j is a logging framework, i.e. it provides the code to log messages. Commons-logging is an abstraction layer for logging frameworks, it doesn't log anything itself. For example if I write code using commons logging and deploy it on JBoss, the logging is done by log4j, but if I deploy it on WebSphere logging is done by WebSphere's own logging implementation. If I run the same code as a stand alone application it Java's own logging that is used
Upvotes: 8
Reputation: 456
Apache Commons Logging is an abstraction for the concrete implementation. It uses log4j, if present and configured. I would use Commons logging in my code and log4j as logging implementation.
Upvotes: 20