What's JCL?
When we are logging, we often use log4j or JDK1.4 in the future, but what is JCL, JCL is Jakarta Commons log tool, he is a bridge between various logging tools, Commons-logging helps you to switch log tools without recompiling the program, such as by switching the JDK built-in log tool to the log4j log tool;
JCL can be downloaded to the http://jakarta.apache.org/commons/logging site;
How to use JCL
JCL mainly consists of two important components, org.apache.commons.loggging.LogFactory (a specific factory class) and his return instance, This example implements the Org.apache.commons.logging.Log interface, JCL configuration is the least, in most cases, you only need to put Commons-logging.jar pack under Classpath; Logfactory provides excellent log detection capabilities, he First you will find the Log4j.jar below the classpath if you don't find it, you will find the jdk1.4+ version;
In the code, we just type:
Import Org.apache.commons.logging.Log; Import Org.apache.commons.logging.LogFactory; ... private static log log = Logfactory.getlog (Testthread.class);
And when we use log4j, we must use:
Import Org.apache.log4j.Logger; .... private Logger log = Logger.getlogger (Testthread.class);.
The log4j and code have to be strongly coupled;