Why we need apache common logging jars to install spring framework in eclipse

Commons Logging is the logging framework that Spring uses to log its own data:

http://blog.springsource.org/2009/12/04/logging-dependencies-in-spring/

Spring is a product like any other product, and as such, it does logging of its own. It uses Commons Logging as an API to perform logging.

You don't need to know Commons Logging inside-out in order to learn Spring; but you need to install Commons Logging for the Spring Framework to work.

You don't "install Spring in Eclipse". Eclipse is an IDE. You need to simply download Spring and make it available to your Eclipse projects, by editing your project's build path (right click the project and choose "Properties").

(Making Spring available for a JavaEE application is a bit more involved. Information about it is readily available within a simple Google search)


Yes, It is necessary to include commons-logging dependency in a spring project. Logging is a very important dependency for Spring because

a) it is the only mandatory external dependency
b) everyone likes to see some output from the tools they are using
c) Spring integrates with lots of other tools all of which have also made a choice of logging dependency.

One of the goals of an application developer is often to have unified logging configured in a central place for the whole application, including all external components.
In almost all enterprise or webapp projects there is a need to log all the information related to error, debug, info(other important infomation/event) to be stored somewhere. In practical application developers later use these logs to find out error in the code. Thus logging is important.

We can include this dependency in pom.xml while building the project as shown below(when using maven) or we can download commons-logging jar.

<dependencies>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-webmvc</artifactId>
 <version>${spring.version}</version>
 <exclusions>
 <exclusion>
 <artifactId>commons-logging</artifactId>
 <groupId>commons-logging</groupId>
 </exclusion>
 </exclusions>
 </dependency>
 </dependencies>

After downloading the jar/dependency, We need to create the commons-logging.properties in our src folder.

org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger

The Logger class can be any one from these:
1)org.apache.commons.logging.impl.Log4JLogger
2)org.apache.commons.logging.impl.Jdk14Logger
3)org.apache.commons.logging.impl.SimpleLog

We need to add the log4j.properties to the src folder.

log4j.rootLogger=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\\logger.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Now, with both the libraries configured we can use them in our Class:

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    public class HowToLog
    {
         private static Log logger = LogFactory.getLog(HowToLog.class);
          public static void main(String[] args){
                logger.info("Log info");
               logger.debug("Debug info");

     }
   }

logger.log:

2015-01-30 22:12:20 INFO  HowToLog:14 - Log info
2015-01-30 22:12:20 DEBUG HowToLog:15 - Debug info