From ee2deb487f1bbf182852cf68b56f75bb1c77cbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=A0=E6=B3=A2?= Date: Tue, 8 Dec 2015 21:13:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AF=E4=BB=A5=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E7=B3=BB=E7=BB=9F=E5=8F=98=E9=87=8F=E6=9D=A5=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=97=A5=E5=BF=97=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../druid/support/logging/LogFactory.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alibaba/druid/support/logging/LogFactory.java b/src/main/java/com/alibaba/druid/support/logging/LogFactory.java index 2a1114a8f3..0390d73bf3 100644 --- a/src/main/java/com/alibaba/druid/support/logging/LogFactory.java +++ b/src/main/java/com/alibaba/druid/support/logging/LogFactory.java @@ -23,8 +23,21 @@ public class LogFactory { private static Constructor logConstructor; static { - // TODO add slf4j logging - + String logType= System.getProperty("druid.logType"); + if(logType != null){ + if(logType.equalsIgnoreCase("slf4j")){ + tryImplementation("org.slf4j.Logger", "com.alibaba.druid.support.logging.SLF4JImpl"); + }else if(logType.equalsIgnoreCase("log4j")){ + tryImplementation("org.apache.log4j.Logger", "com.alibaba.druid.support.logging.Log4jImpl"); + }else if(logType.equalsIgnoreCase("log4j2")){ + tryImplementation("org.apache.logging.log4j.Logger", "com.alibaba.druid.support.logging.Log4j2Impl"); + }else if(logType.equalsIgnoreCase("commonsLog")){ + tryImplementation("org.apache.commons.logging.LogFactory", + "com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl"); + }else if(logType.equalsIgnoreCase("jdkLog")){ + tryImplementation("java.util.logging.Logger", "com.alibaba.druid.support.logging.Jdk14LoggingImpl"); + } + } // 优先选择log4j,而非Apache Common Logging. 因为后者无法设置真实Log调用者的信息 tryImplementation("org.apache.log4j.Logger", "com.alibaba.druid.support.logging.Log4jImpl"); tryImplementation("org.apache.logging.log4j.Logger", "com.alibaba.druid.support.logging.Log4j2Impl");