Browse Source

无jira任务 fix: druid log4j适配

feature/x
lidongy 3 years ago
parent
commit
57a3de81ad
  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");
* 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();

Loading…
Cancel
Save