前言
通过commons-logging-1.1.1架构来实现log4j,sl4j,jdk的log等日志管理系统的接口.使log系统更容易切换
一 包
commons-logging-1.1.1.jar
log4j-1.2.16.jar
二 src下的文件
log4j.properties
log4j.rootLogger=DEBUG,appender1,appender2
log4j.appender.appender1=org.apache.log4j.ConsoleAppender
log4j.appender.appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.appender1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}[%p]: %m%n
# 立即输出
log4j.appender.appender1.immediateFlush=true
commons-logging.properties
# 此配置文件可以省略,默认就是使用的log4j
# 必须要有commons-logging-1.1.1.jar;
# commons-logging-adapters-1.1.1.jar,commons-logging-api-1.1.1.jar为可选
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
三 调用
- package com.phl;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- public class Test {
- private static Log log = LogFactory.getLog(Test.class);
- public static void main(String[] args) {
- log.debug("hello commons-logging!");
- }
- }