Apache commons-logging Usages

Source: Internet
Author: User
Tags wrapper log4j

1. Commons-loggin Introduction

Jakarta Commons Logging (JCL) provides a log (logging) interface (interface), taking into account both lightweight and not-dependent log implementation tools. It provides middleware/log tool developers with a simple log operation abstraction that allows program developers to implement tools with different specific log implementations. The user is assumed to be familiar with a higher level of detail for some kind of log implementation tool. JCL provides a simple wrapper for other log tools, including log4j, Avalon Logkit, and JDK 1.4, which is closer to log4j and Logkit implementations.

2. Quick Start

JCL has two basic abstract classes: log (base logger) and logfactory (responsible for creating the log instance). When Commons-logging.jar is added to the classpath, it makes a reasonable guess at the log tool you want to use and then sets it up, and the user doesn't have to do anything. The default logfactory is to follow the steps below to discover and determine which log tool will be used (in order, the search process will be aborted when the first tool is found):

1. Find the value in the current factory named Org.apache.commons.logging.Log configuration property

2. Find the value in the system named Org.apache.commons.logging.Log in the attribute

3. Use the associated wrapper (wrapper) class (Log4jlogger) If there is a log4j in the classpath of the application

4. If the application is running in a jdk1.4 system, use the associated wrapper class (Jdk14logger)

5. Use simple log packing class (Simplelog)

The specific implementation of ORG.APACHE.COMMONS.LOGGING.LOG is as follows:

-org.apache.commons.logging.impl.jdk14logger use JDK1.4.

-org.apache.commons.logging.impl.log4jlogger use log4j.

-org.apache.commons.logging.impl.logkitlogger use Avalon-logkit.

-org.apache.commons.logging.impl.simplelog common-logging the implementation of the class with its own log. It implements the log interface, and outputs the log messages to the system error stream system.err.

-org.apache.commons.logging.impl.nooplog common-logging the implementation of the class with its own log. It implements the log interface. No action is made in the method of its output log.

3. Using JCL Development

Because log4j is powerful, developers don't want to be too dependent on log4j. So at present more popular is commons-logging and log4j combine use.

1. Deployment Log Device

Download the Commons-logging.jar and Log4j.jar packages, and then put them in the project's Lib directory and introduce them into the project.

2. Specify the log device

Set the class that implements the interface in the property file Common-logging.properties. as follows (set log4j here for the log pack used):

#commons-logging.properties文件配置信息
# org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
# Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
#利用log4j为输出介质
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog
#JDK5 Logger
#org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.