I was reading some of the tutorials and some of them are adding apache common logging jars in order to use/install spring framework instead. I have no knowledge about apache common logging.Is it necessary to install apache common logging if I want to work/learn with/from spring/springMVC.What is exactly is apache common logging? What is the most preferable way to install spring in eclipse.
Thanks
To install Spring Framework there are several steps have to be followed which are- Setup Java Development Kit (JDK) Installing Apache Common Logging API Setup Eclipse IDE
A common choice might be to bridge Spring to SLF4J, and then provide explicit binding from SLF4J to Log4J. You need to supply 4 dependencies (and exclude the existing commons-logging): the bridge, theSLF4J API, the binding to Log4J, and the Log4J implementation itself. In Maven you would do that like this
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, and c) Spring integrates with lots of other tools all of which have also made a choice of logging dependency.
The Apache Commons Logging (JCL) provides a Log interface that is intended to be both light-weight and an independent abstraction of other logging toolkits. It provides the middleware/tooling developer with a simple logging abstraction, that allows the user (application developer) to plug in a specific logging implementation.
Apache Common Logging is used for logging the status of spring system. Without this library, the spring framework could not work properly.
In my computer, I use myeclipse instead which could help u add spring capability.
Best
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With