Another powerful feature of the Commons Logging package (Web site management)
Another powerful feature of the Commons Logging package is that it is completely extensible. If you are using a logging package that is not yet supported, you can create an adapter to that implementation by extending the appropriate components, and your application can use the Commons Logging API. 15.3.1 Installing the Commons Logging Package You can download the latest source and binary code for the Commons Logging package at http://jakarta.apache.org/commons/logging.html. Struts 1.1 already includes commons-logging.jar, which is the only required binary file. Unless you want the absolute latest from the nightly build, the version included with the Struts framework should suit your needs. You should place the commons- logging.jar file into the WEB-INF/lib directory for the web application. You will also need to decide on a logging implementation. The Commons Logging package includes an implementation called SimpleLog that writes log messages to stdoutand stderr. If you don’t want to worry about getting log4j working and are not using Java 1.4, the SimpleLog implementation is a good choice to get things started. Once you decide on an implementation, you must configure the implementation class so that the Commons Logging factory component can discover it at application startup. There are many ways to do this, but the easiest is to create a properties file called commons-logging.properties that contains the class name of the logging implementation. The most important property key in this file is the org.apache.commons.logging.Log key, which is used to set the implementation class. The following illustrates how to set up the Commons Logging package to use the SimpleLog implementation: org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog At runtime, the logging component will search for the commons-logging.properties file and attempt to instantiate the fully qualified class name found there. The class name specified must be available to the web application class loader. The properties file should be placed in the WEB-INF/classesdirectory. To switch to log4j, all you need to do is switch the class name in the commons-logging.properties file, like this: org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog Note that you still need to configure log4j for your environment, including creating a log4j.properties file. Each logging implementation may have different configuration requirements that must be satisfied. 15.3.2 Using the Commons Logging API Once the configuration steps are completed, your application is ready to use the Commons Logging API. You must include the following import statements in each class or component in which you wish to use the logging API: import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
In case you need quality webspace to host and run your web applications, try our personal web hosting services.