Browse Source

Pull request #4384: 无jira任务 fix: druid log4j适配

Merge in CORE/base-third from ~LIDONGY/base-third:feature/x to feature/x

* commit '57a3de81ad026100c69f36f64c14b9d6e3664da0':
  无jira任务 fix: druid log4j适配
feature/x
lidongy 3 years ago
parent
commit
f4ea57c27b
  1. 31
      fine-druid/src/main/java/com/fr/third/alibaba/druid/support/logging/LogFactory.java

31
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); String logType= System.getProperty("druid.logType");
if(logType != null){ if(logType != null){
if(logType.equalsIgnoreCase("slf4j")){ 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")){ }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")){ }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")){ }else if(logType.equalsIgnoreCase("commonsLog")){
tryImplementation("org.apache.commons.logging.LogFactory", tryImplementation("org.apache.commons.logging.LogFactory",
"com.fr.third.alibaba.druid.support.logging.JakartaCommonsLoggingImpl"); "JakartaCommonsLoggingImpl");
}else if(logType.equalsIgnoreCase("jdkLog")){ }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防止漏洞 // 优先选择log4j2防止漏洞
tryImplementation("com.fr.third.apache.logging.log4j.Logger", "FRLog4j2Impl"); tryImplementation("com.fr.third.apache.logging.log4j.Logger", "FRLog4j2Impl");
// 优先选择log4j,而非Apache Common Logging. 因为后者无法设置真实Log调用者的信息 // 优先选择log4j,而非Apache Common Logging. 因为后者无法设置真实Log调用者的信息
tryImplementation("com.fr.third.apache.log4j.Logger", "FRLog4jImpl"); 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", "Log4jImpl");
tryImplementation("org.apache.log4j.Logger", "com.fr.third.alibaba.druid.support.logging.Log4jImpl"); tryImplementation("org.apache.logging.log4j.Logger", "Log4j2Impl");
tryImplementation("org.apache.logging.log4j.Logger", "com.fr.third.alibaba.druid.support.logging.Log4j2Impl"); tryImplementation("org.slf4j.Logger", "SLF4JImpl");
tryImplementation("org.apache.commons.logging.LogFactory", tryImplementation("org.apache.commons.logging.LogFactory", "JakartaCommonsLoggingImpl");
"com.fr.third.alibaba.druid.support.logging.JakartaCommonsLoggingImpl"); tryImplementation("java.util.logging.Logger", "Jdk14LoggingImpl");
tryImplementation("java.util.logging.Logger", "com.fr.third.alibaba.druid.support.logging.Jdk14LoggingImpl");
if (logConstructor == null) { if (logConstructor == null) {
try { try {
@ -66,7 +65,13 @@ public class LogFactory {
try { try {
Resources.classForName(testClassName); 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 }); logConstructor = implClass.getConstructor(new Class[] { String.class });
Class<?> declareClass = logConstructor.getDeclaringClass(); Class<?> declareClass = logConstructor.getDeclaringClass();

Loading…
Cancel
Save