[ISSUE#11956] Fix logging module old bugs (#12011)
* Remove log4j dependencies from nacos-client. * Fix logback listener don't add to context. * Fix can't adapter low version logback below 1.1.10. * For checkstyle.
This commit is contained in:
parent
de10c07146
commit
da3e88b3d4
@ -73,24 +73,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
~ Copyright 1999-2023 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.
|
||||
|
@ -20,7 +20,6 @@ import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.spi.LoggerContextListener;
|
||||
import ch.qos.logback.core.CoreConstants;
|
||||
import com.alibaba.nacos.common.logging.NacosLoggingAdapter;
|
||||
import com.alibaba.nacos.common.logging.NacosLoggingProperties;
|
||||
import com.alibaba.nacos.common.utils.ResourceUtils;
|
||||
@ -91,7 +90,7 @@ public class LogbackNacosLoggingAdapter implements NacosLoggingAdapter {
|
||||
String location = loggingProperties.getLocation();
|
||||
configurator.setLoggingProperties(loggingProperties);
|
||||
LoggerContext loggerContext = loadConfigurationOnStart(location);
|
||||
if (loggerContext.getObject(CoreConstants.RECONFIGURE_ON_CHANGE_TASK) != null && hasNoListener(loggerContext)) {
|
||||
if (hasNoListener(loggerContext)) {
|
||||
addListener(loggerContext, location);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,12 @@ public class NacosLogbackConfiguratorAdapterV1 extends JoranConfigurator {
|
||||
URLConnection urlConnection = url.openConnection();
|
||||
urlConnection.setUseCaches(false);
|
||||
in = urlConnection.getInputStream();
|
||||
if (hasNewDoConfigureApi()) {
|
||||
doConfigure(in, url.toExternalForm());
|
||||
} else {
|
||||
// adapter old version of logback below 1.1.10
|
||||
doConfigure(in);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
String errMsg = "Could not open URL [" + url + "].";
|
||||
addError(errMsg, ioe);
|
||||
@ -89,4 +94,17 @@ public class NacosLogbackConfiguratorAdapterV1 extends JoranConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Since logback 1.1.10, Add new doConfigure API with sax systemId and use this API to do configure.
|
||||
*
|
||||
* @return {@code true} when logback is upper 1.1.10, otherwise {@code false}
|
||||
*/
|
||||
private boolean hasNewDoConfigureApi() {
|
||||
try {
|
||||
this.getClass().getMethod("doConfigure", InputStream.class, String.class);
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user