From 57a3de81ad026100c69f36f64c14b9d6e3664da0 Mon Sep 17 00:00:00 2001 From: lidongy <1879087903@qq.com> Date: Mon, 13 Dec 2021 11:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20fix:=20druid?= =?UTF-8?q?=20log4j=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../druid/support/logging/LogFactory.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/fine-druid/src/main/java/com/fr/third/alibaba/druid/support/logging/LogFactory.java b/fine-druid/src/main/java/com/fr/third/alibaba/druid/support/logging/LogFactory.java index ef8b4d0bc..fa831f17e 100644 --- a/fine-druid/src/main/java/com/fr/third/alibaba/druid/support/logging/LogFactory.java +++ b/fine-druid/src/main/java/com/fr/third/alibaba/druid/support/logging/LogFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2018 Alibaba Group Holding Ltd. + * Copyright 1999-2017 Alibaba Group Holding Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,28 +26,27 @@ public class LogFactory { String logType= System.getProperty("druid.logType"); if(logType != null){ if(logType.equalsIgnoreCase("slf4j")){ - tryImplementation("org.slf4j.Logger", "com.fr.third.alibaba.druid.support.logging.SLF4JImpl"); + tryImplementation("org.slf4j.Logger", "SLF4JImpl"); }else if(logType.equalsIgnoreCase("log4j")){ - tryImplementation("org.apache.log4j.Logger", "com.fr.third.alibaba.druid.support.logging.Log4jImpl"); + tryImplementation("org.apache.log4j.Logger", "Log4jImpl"); }else if(logType.equalsIgnoreCase("log4j2")){ - tryImplementation("org.apache.logging.log4j.Logger", "com.fr.third.alibaba.druid.support.logging.Log4j2Impl"); + tryImplementation("org.apache.logging.log4j.Logger", "Log4j2Impl"); }else if(logType.equalsIgnoreCase("commonsLog")){ tryImplementation("org.apache.commons.logging.LogFactory", - "com.fr.third.alibaba.druid.support.logging.JakartaCommonsLoggingImpl"); + "JakartaCommonsLoggingImpl"); }else if(logType.equalsIgnoreCase("jdkLog")){ - tryImplementation("java.util.logging.Logger", "com.fr.third.alibaba.druid.support.logging.Jdk14LoggingImpl"); + tryImplementation("java.util.logging.Logger", "Jdk14LoggingImpl"); } } // 优先选择log4j2防止漏洞 tryImplementation("com.fr.third.apache.logging.log4j.Logger", "FRLog4j2Impl"); // 优先选择log4j,而非Apache Common Logging. 因为后者无法设置真实Log调用者的信息 tryImplementation("com.fr.third.apache.log4j.Logger", "FRLog4jImpl"); - tryImplementation("org.slf4j.Logger", "com.fr.third.alibaba.druid.support.logging.SLF4JImpl"); - tryImplementation("org.apache.log4j.Logger", "com.fr.third.alibaba.druid.support.logging.Log4jImpl"); - tryImplementation("org.apache.logging.log4j.Logger", "com.fr.third.alibaba.druid.support.logging.Log4j2Impl"); - tryImplementation("org.apache.commons.logging.LogFactory", - "com.fr.third.alibaba.druid.support.logging.JakartaCommonsLoggingImpl"); - tryImplementation("java.util.logging.Logger", "com.fr.third.alibaba.druid.support.logging.Jdk14LoggingImpl"); + tryImplementation("org.apache.log4j.Logger", "Log4jImpl"); + tryImplementation("org.apache.logging.log4j.Logger", "Log4j2Impl"); + tryImplementation("org.slf4j.Logger", "SLF4JImpl"); + tryImplementation("org.apache.commons.logging.LogFactory", "JakartaCommonsLoggingImpl"); + tryImplementation("java.util.logging.Logger", "Jdk14LoggingImpl"); if (logConstructor == null) { try { @@ -66,7 +65,13 @@ public class LogFactory { try { Resources.classForName(testClassName); - Class implClass = Resources.classForName(implClassName); + Class implClass = null; + try { + implClass = Resources.classForName(implClassName); + } catch (Throwable t) { + implClassName = "com.fr.third.alibaba.druid.support.logging." + implClassName; + implClass = Resources.classForName(implClassName); + } logConstructor = implClass.getConstructor(new Class[] { String.class }); Class declareClass = logConstructor.getDeclaringClass();