This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new c8e9ff74d [type:refactor] refactor shenyu-logging (#3684)
c8e9ff74d is described below
commit c8e9ff74d1c176ec9e39a56922d33c25d9562aa4
Author: moremind <[email protected]>
AuthorDate: Sun Jul 10 09:24:51 2022 +0800
[type:refactor] refactor shenyu-logging (#3684)
* [type:refactor] refactor shenyu-logging
* [type:refactor] fix checkstyle
---
.../test/http/combination/RocketMqPluginTest.java | 3 +-
.../plugin/aliyun/sls/config/LogCollectConfig.java | 6 ++-
.../handler/LoggingAliYunSlsPluginDataHandler.java | 3 +-
.../sls/utils/AliyunSlsLogCollectConfigUtils.java | 54 ----------------------
.../aliyunsls/AliyunSlsLogCollectClientTest.java | 3 +-
.../elasticsearch/config/LogCollectConfig.java | 6 ++-
.../LoggingElasticSearchPluginDataHandler.java | 3 +-
.../utils/ElasticSearchLogCollectConfigUtils.java | 54 ----------------------
.../client/ElasticSearchLogCollectClientTest.java | 5 +-
.../logging/kafka/config/LogCollectConfig.java | 6 ++-
.../handler/LoggingKafkaPluginDataHandler.java | 3 +-
.../logging/kafka/kafka/KafkaLogCollectClient.java | 3 +-
.../kafka/utils/KafkaLogCollectConfigUtils.java | 25 ----------
.../rocketmq/client/RocketMQLogCollectClient.java | 3 +-
.../logging/rocketmq/config/LogCollectConfig.java | 6 ++-
.../handler/LoggingRocketMQPluginDataHandler.java | 3 +-
.../utils/RocketLogCollectConfigUtils.java | 25 ----------
.../client/RocketMQLogCollectClientTest.java | 3 +-
.../pom.xml | 5 --
19 files changed, 33 insertions(+), 186 deletions(-)
diff --git
a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RocketMqPluginTest.java
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RocketMqPluginTest.java
index 84d92b8f2..40891f3a5 100644
---
a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RocketMqPluginTest.java
+++
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/RocketMqPluginTest.java
@@ -25,7 +25,6 @@ import
org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog;
import org.apache.shenyu.plugin.logging.rocketmq.config.LogCollectConfig;
import
org.apache.shenyu.plugin.logging.rocketmq.client.RocketMQLogCollectClient;
import org.apache.shenyu.plugin.logging.rocketmq.constant.LoggingConstant;
-import
org.apache.shenyu.plugin.logging.rocketmq.utils.RocketLogCollectConfigUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -70,7 +69,7 @@ public final class RocketMqPluginTest extends
AbstractPluginDataInit {
logs.add(shenyuRequestLog);
String msg = "";
- RocketLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
rocketMQLogCollectClient.initProducer(properties);
try {
rocketMQLogCollectClient.consume(logs);
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/config/LogCollectConfig.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/config/LogCollectConfig.java
index 8737841fd..44758fe48 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/config/LogCollectConfig.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/config/LogCollectConfig.java
@@ -19,11 +19,15 @@ package org.apache.shenyu.plugin.aliyun.sls.config;
import org.apache.shenyu.plugin.logging.common.config.GenericGlobalConfig;
+import java.util.Optional;
+
/**
* LogCollectConfig.
*/
public class LogCollectConfig {
+ public static final LogCollectConfig INSTANCE = new LogCollectConfig();
+
private GlobalLogConfig globalLogConfig;
/**
@@ -32,7 +36,7 @@ public class LogCollectConfig {
* @return global log config
*/
public GlobalLogConfig getGlobalLogConfig() {
- return globalLogConfig;
+ return Optional.ofNullable(globalLogConfig).orElse(new
GlobalLogConfig());
}
/**
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/handler/LoggingAliYunSlsPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/handler/LoggingAliYunSlsPluginDataHandler.java
index 6726f1731..225f775a1 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/handler/LoggingAliYunSlsPluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/handler/LoggingAliYunSlsPluginDataHandler.java
@@ -26,7 +26,6 @@ import
org.apache.shenyu.plugin.aliyun.sls.collector.DefaultLogCollector;
import org.apache.shenyu.plugin.aliyun.sls.aliyunsls.AliyunSlsLogCollectClient;
import org.apache.shenyu.plugin.aliyun.sls.config.LogCollectConfig;
import org.apache.shenyu.plugin.aliyun.sls.constant.LoggingConstant;
-import
org.apache.shenyu.plugin.aliyun.sls.utils.AliyunSlsLogCollectConfigUtils;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,7 +54,7 @@ public class LoggingAliYunSlsPluginDataHandler implements
PluginDataHandler {
}
if (Objects.isNull(exist) || !globalLogConfig.equals(exist)) {
// no data, init client
-
AliyunSlsLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
Properties properties = new Properties();
properties.setProperty(LoggingConstant.ACCESS_ID,
globalLogConfig.getAccessId().trim());
properties.setProperty(LoggingConstant.ACCESS_KEY,
globalLogConfig.getAccessKey().trim());
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/utils/AliyunSlsLogCollectConfigUtils.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/utils/AliyunSlsLogCollectConfigUtils.java
deleted file mode 100644
index 12dba54ef..000000000
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/utils/AliyunSlsLogCollectConfigUtils.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shenyu.plugin.aliyun.sls.utils;
-
-import org.apache.shenyu.plugin.aliyun.sls.config.LogCollectConfig;
-
-import java.util.Optional;
-
-/**
- * AliyunSlsLogCollectConfigUtils.
- */
-public final class AliyunSlsLogCollectConfigUtils {
-
- private static LogCollectConfig.GlobalLogConfig globalLogConfig;
-
- private static final LogCollectConfig.GlobalLogConfig
DEFAULT_GLOBAL_LOG_CONFIG =
- new LogCollectConfig.GlobalLogConfig();
-
- public AliyunSlsLogCollectConfigUtils() {
- }
-
- /**
- * set global config.
- *
- * @param config global config
- */
- public static void setGlobalConfig(final LogCollectConfig.GlobalLogConfig
config) {
- globalLogConfig = config;
- }
-
- /**
- * get global config.
- *
- * @return {@linkplain LogCollectConfig.GlobalLogConfig}
- */
- public static LogCollectConfig.GlobalLogConfig getGlobalLogConfig() {
- return
Optional.ofNullable(globalLogConfig).orElse(DEFAULT_GLOBAL_LOG_CONFIG);
- }
-}
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
index 66d3ccae8..59cc14075 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
@@ -21,7 +21,6 @@ import org.apache.shenyu.common.dto.PluginData;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.plugin.aliyun.sls.config.LogCollectConfig;
import org.apache.shenyu.plugin.aliyun.sls.constant.LoggingConstant;
-import
org.apache.shenyu.plugin.aliyun.sls.utils.AliyunSlsLogCollectConfigUtils;
import org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@@ -87,7 +86,7 @@ public class AliyunSlsLogCollectClientTest {
@Test
public void testConsume() {
String msg = "";
- AliyunSlsLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
aliyunSlsLogCollectClient.initClient(props);
try {
aliyunSlsLogCollectClient.consume(logs);
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/config/LogCollectConfig.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/config/LogCollectConfig.java
index 69a443238..806b347f0 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/config/LogCollectConfig.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/config/LogCollectConfig.java
@@ -19,6 +19,8 @@ package org.apache.shenyu.plugin.logging.elasticsearch.config;
import org.apache.shenyu.plugin.logging.common.config.GenericGlobalConfig;
+import java.util.Optional;
+
/**
* log collect config, include elasticsearch config.
* Host and port must be included, and others are optional.
@@ -26,6 +28,8 @@ import
org.apache.shenyu.plugin.logging.common.config.GenericGlobalConfig;
*/
public class LogCollectConfig {
+ public static final LogCollectConfig INSTANCE = new LogCollectConfig();
+
private GlobalLogConfig globalLogConfig;
/**
@@ -34,7 +38,7 @@ public class LogCollectConfig {
* @return global log config
*/
public GlobalLogConfig getGlobalLogConfig() {
- return globalLogConfig;
+ return Optional.ofNullable(globalLogConfig).orElse(new
GlobalLogConfig());
}
/**
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/handler/LoggingElasticSearchPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/handler/LoggingElasticSearchPluginDataHandler.java
index bd795e85d..f501dc08e 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/handler/LoggingElasticSearchPluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/handler/LoggingElasticSearchPluginDataHandler.java
@@ -30,7 +30,6 @@ import
org.apache.shenyu.plugin.logging.elasticsearch.collector.DefaultLogCollec
import org.apache.shenyu.plugin.logging.elasticsearch.config.LogCollectConfig;
import org.apache.shenyu.plugin.logging.elasticsearch.constant.LoggingConstant;
import
org.apache.shenyu.plugin.logging.elasticsearch.client.ElasticSearchLogCollectClient;
-import
org.apache.shenyu.plugin.logging.elasticsearch.utils.ElasticSearchLogCollectConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,7 +63,7 @@ public class LoggingElasticSearchPluginDataHandler implements
PluginDataHandler
LogCollectConfig.GlobalLogConfig globalLogConfig =
GsonUtils.getInstance().fromJson(pluginData.getConfig(),
LogCollectConfig.GlobalLogConfig.class);
-
ElasticSearchLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
Properties properties = new Properties();
properties.setProperty(LoggingConstant.HOST,
globalLogConfig.getHost());
properties.setProperty(LoggingConstant.PORT,
globalLogConfig.getPort());
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/utils/ElasticSearchLogCollectConfigUtils.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/utils/ElasticSearchLogCollectConfigUtils.java
deleted file mode 100644
index f18e60bd4..000000000
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/main/java/org/apache/shenyu/plugin/logging/elasticsearch/utils/ElasticSearchLogCollectConfigUtils.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shenyu.plugin.logging.elasticsearch.utils;
-
-import org.apache.shenyu.plugin.logging.elasticsearch.config.LogCollectConfig;
-
-import java.util.Optional;
-
-/**
- * ElasticSearchLogCollectConfig utils.
- */
-public class ElasticSearchLogCollectConfigUtils {
-
- private static LogCollectConfig.GlobalLogConfig globalLogConfig;
-
- private static final LogCollectConfig.GlobalLogConfig
DEFAULT_GLOBAL_LOG_CONFIG =
- new LogCollectConfig.GlobalLogConfig();
-
- public ElasticSearchLogCollectConfigUtils() {
- }
-
- /**
- * set global config.
- *
- * @param config global config
- */
- public static void setGlobalConfig(final LogCollectConfig.GlobalLogConfig
config) {
- globalLogConfig = config;
- }
-
- /**
- * get global config.
- *
- * @return {@linkplain LogCollectConfig.GlobalLogConfig}
- */
- public static LogCollectConfig.GlobalLogConfig getGlobalLogConfig() {
- return
Optional.ofNullable(globalLogConfig).orElse(DEFAULT_GLOBAL_LOG_CONFIG);
- }
-}
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/test/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClientTest.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/test/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClientTest.java
index 8cc603d45..d791f41a8 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/test/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClientTest.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-elasticsearch/src/test/java/org/apache/shenyu/plugin/logging/elasticsearch/client/ElasticSearchLogCollectClientTest.java
@@ -22,7 +22,6 @@ import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog;
import org.apache.shenyu.plugin.logging.elasticsearch.config.LogCollectConfig;
import org.apache.shenyu.plugin.logging.elasticsearch.constant.LoggingConstant;
-import
org.apache.shenyu.plugin.logging.elasticsearch.utils.ElasticSearchLogCollectConfigUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -66,7 +65,7 @@ public class ElasticSearchLogCollectClientTest {
@Test
public void testConsume() {
String msg = "";
- ElasticSearchLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
elasticSearchLogCollectClient.initClient(properties);
try {
elasticSearchLogCollectClient.consume(logs);
@@ -79,7 +78,7 @@ public class ElasticSearchLogCollectClientTest {
@Test
public void testCreateIndex() {
- ElasticSearchLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
elasticSearchLogCollectClient.initClient(properties);
elasticSearchLogCollectClient.createIndex("test");
}
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/config/LogCollectConfig.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/config/LogCollectConfig.java
index 638174e4c..305dd2710 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/config/LogCollectConfig.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/config/LogCollectConfig.java
@@ -19,6 +19,8 @@ package org.apache.shenyu.plugin.logging.kafka.config;
import org.apache.shenyu.plugin.logging.common.config.GenericGlobalConfig;
+import java.util.Optional;
+
/**
* log collect config, include kafka config.
* Topic and nameserver must be included, and others are optional.
@@ -26,6 +28,8 @@ import
org.apache.shenyu.plugin.logging.common.config.GenericGlobalConfig;
*/
public class LogCollectConfig {
+ public static final LogCollectConfig INSTANCE = new LogCollectConfig();
+
private GlobalLogConfig globalLogConfig;
/**
@@ -34,7 +38,7 @@ public class LogCollectConfig {
* @return global log config
*/
public GlobalLogConfig getGlobalLogConfig() {
- return globalLogConfig;
+ return Optional.ofNullable(globalLogConfig).orElse(new
GlobalLogConfig());
}
/**
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/handler/LoggingKafkaPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/handler/LoggingKafkaPluginDataHandler.java
index 09c9ab47c..b9bf89238 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/handler/LoggingKafkaPluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/handler/LoggingKafkaPluginDataHandler.java
@@ -37,7 +37,6 @@ import
org.apache.shenyu.plugin.logging.kafka.collector.DefaultLogCollector;
import org.apache.shenyu.plugin.logging.kafka.config.LogCollectConfig;
import org.apache.shenyu.plugin.logging.kafka.constant.LoggingConstant;
import org.apache.shenyu.plugin.logging.kafka.kafka.KafkaLogCollectClient;
-import org.apache.shenyu.plugin.logging.kafka.utils.KafkaLogCollectConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -93,7 +92,7 @@ public class LoggingKafkaPluginDataHandler implements
PluginDataHandler {
LogCollectConfig.GlobalLogConfig globalLogConfig =
GsonUtils.getInstance().fromJson(pluginData.getConfig(),
LogCollectConfig.GlobalLogConfig.class);
- KafkaLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
// start kafka producer
Properties properties = new Properties();
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
StringSerializer.class.getName());
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/kafka/KafkaLogCollectClient.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/kafka/KafkaLogCollectClient.java
index b6baccef2..befc12e2e 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/kafka/KafkaLogCollectClient.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/kafka/KafkaLogCollectClient.java
@@ -36,6 +36,7 @@ import org.apache.shenyu.common.utils.JsonUtils;
import org.apache.shenyu.plugin.logging.common.client.LogConsumeClient;
import org.apache.shenyu.plugin.logging.common.entity.LZ4CompressData;
import org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog;
+import org.apache.shenyu.plugin.logging.kafka.config.LogCollectConfig;
import org.apache.shenyu.plugin.logging.kafka.constant.LoggingConstant;
import org.apache.shenyu.plugin.logging.kafka.utils.KafkaLogCollectConfigUtils;
import org.slf4j.Logger;
@@ -117,7 +118,7 @@ public class KafkaLogCollectClient implements
LogConsumeClient {
private ProducerRecord<String, String> toProducerRecord(final String
logTopic, final ShenyuRequestLog log) {
byte[] bytes = JsonUtils.toJson(log).getBytes(StandardCharsets.UTF_8);
- String compressAlg =
StringUtils.defaultIfBlank(KafkaLogCollectConfigUtils.getGlobalLogConfig().getCompressAlg(),
"");
+ String compressAlg =
StringUtils.defaultIfBlank(LogCollectConfig.INSTANCE.getGlobalLogConfig().getCompressAlg(),
"");
if ("LZ4".equalsIgnoreCase(compressAlg.trim())) {
LZ4CompressData lz4CompressData = new
LZ4CompressData(bytes.length, compressedByte(bytes));
return new ProducerRecord<>(logTopic,
JsonUtils.toJson(lz4CompressData));
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/utils/KafkaLogCollectConfigUtils.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/utils/KafkaLogCollectConfigUtils.java
index 4871b7ad1..1bd4c5cc6 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/utils/KafkaLogCollectConfigUtils.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-kafka/src/main/java/org/apache/shenyu/plugin/logging/kafka/utils/KafkaLogCollectConfigUtils.java
@@ -17,12 +17,10 @@
package org.apache.shenyu.plugin.logging.kafka.utils;
-import org.apache.shenyu.plugin.logging.kafka.config.LogCollectConfig;
import org.springframework.util.AntPathMatcher;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
/**
* kafka log collect config utils.
@@ -33,32 +31,9 @@ public class KafkaLogCollectConfigUtils {
private static Map<String, String> apiTopicMap = new HashMap<>();
- private static LogCollectConfig.GlobalLogConfig globalLogConfig;
-
- private static final LogCollectConfig.GlobalLogConfig
DEFAULT_GLOBAL_LOG_CONFIG =
- new LogCollectConfig.GlobalLogConfig();
-
public KafkaLogCollectConfigUtils() {
}
- /**
- * set global config.
- *
- * @param config global config
- */
- public static void setGlobalConfig(final LogCollectConfig.GlobalLogConfig
config) {
- globalLogConfig = config;
- }
-
- /**
- * get global config.
- *
- * @return {@linkplain LogCollectConfig.GlobalLogConfig}
- */
- public static LogCollectConfig.GlobalLogConfig getGlobalLogConfig() {
- return
Optional.ofNullable(globalLogConfig).orElse(DEFAULT_GLOBAL_LOG_CONFIG);
- }
-
/**
* set api topic map.
* @param uriTopicMap api topic map
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClient.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClient.java
index 8a90dd8b0..c3e4f9e7c 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClient.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClient.java
@@ -27,6 +27,7 @@ import org.apache.rocketmq.common.message.Message;
import org.apache.shenyu.common.utils.JsonUtils;
import org.apache.shenyu.plugin.logging.common.client.LogConsumeClient;
import org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog;
+import org.apache.shenyu.plugin.logging.rocketmq.config.LogCollectConfig;
import org.apache.shenyu.plugin.logging.rocketmq.constant.LoggingConstant;
import org.apache.shenyu.plugin.logging.common.entity.LZ4CompressData;
import
org.apache.shenyu.plugin.logging.rocketmq.utils.RocketLogCollectConfigUtils;
@@ -110,7 +111,7 @@ public class RocketMQLogCollectClient implements
LogConsumeClient {
private Message toMessage(final String logTopic, final ShenyuRequestLog
log) {
byte[] bytes = JsonUtils.toJson(log).getBytes(StandardCharsets.UTF_8);
- String compressAlg =
StringUtils.defaultIfBlank(RocketLogCollectConfigUtils.getGlobalLogConfig().getCompressAlg(),
"");
+ String compressAlg =
StringUtils.defaultIfBlank(LogCollectConfig.INSTANCE.getGlobalLogConfig().getCompressAlg(),
"");
if ("LZ4".equalsIgnoreCase(compressAlg.trim())) {
LZ4CompressData lz4CompressData = new
LZ4CompressData(bytes.length, compressedByte(bytes));
return new Message(logTopic,
JsonUtils.toJson(lz4CompressData).getBytes(StandardCharsets.UTF_8));
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/config/LogCollectConfig.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/config/LogCollectConfig.java
index f9c57040b..74ce657a4 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/config/LogCollectConfig.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/config/LogCollectConfig.java
@@ -19,6 +19,8 @@ package org.apache.shenyu.plugin.logging.rocketmq.config;
import org.apache.shenyu.plugin.logging.common.config.GenericGlobalConfig;
+import java.util.Optional;
+
/**
* log collect config, include rocketmq config.
* Topic and nameserver must be included, and others are optional.
@@ -26,6 +28,8 @@ import
org.apache.shenyu.plugin.logging.common.config.GenericGlobalConfig;
*/
public class LogCollectConfig {
+ public static final LogCollectConfig INSTANCE = new LogCollectConfig();
+
private GlobalLogConfig globalLogConfig;
/**
@@ -34,7 +38,7 @@ public class LogCollectConfig {
* @return global log config
*/
public GlobalLogConfig getGlobalLogConfig() {
- return globalLogConfig;
+ return Optional.ofNullable(globalLogConfig).orElse(new
GlobalLogConfig());
}
/**
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/handler/LoggingRocketMQPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/handler/LoggingRocketMQPluginDataHandler.java
index 69e687120..235dcf597 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/handler/LoggingRocketMQPluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/handler/LoggingRocketMQPluginDataHandler.java
@@ -30,7 +30,6 @@ import
org.apache.shenyu.plugin.logging.rocketmq.collector.DefaultLogCollector;
import org.apache.shenyu.plugin.logging.rocketmq.config.LogCollectConfig;
import org.apache.shenyu.plugin.logging.rocketmq.constant.LoggingConstant;
import
org.apache.shenyu.plugin.logging.rocketmq.client.RocketMQLogCollectClient;
-import
org.apache.shenyu.plugin.logging.rocketmq.utils.RocketLogCollectConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,7 +64,7 @@ public class LoggingRocketMQPluginDataHandler implements
PluginDataHandler {
LogCollectConfig.GlobalLogConfig globalLogConfig =
GsonUtils.getInstance().fromJson(pluginData.getConfig(),
LogCollectConfig.GlobalLogConfig.class);
- RocketLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
// start rocketmq producer
Properties properties = new Properties();
properties.setProperty(LoggingConstant.TOPIC,
globalLogConfig.getTopic());
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/utils/RocketLogCollectConfigUtils.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/utils/RocketLogCollectConfigUtils.java
index e68d658ed..3d0731a54 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/utils/RocketLogCollectConfigUtils.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/main/java/org/apache/shenyu/plugin/logging/rocketmq/utils/RocketLogCollectConfigUtils.java
@@ -17,12 +17,10 @@
package org.apache.shenyu.plugin.logging.rocketmq.utils;
-import org.apache.shenyu.plugin.logging.rocketmq.config.LogCollectConfig;
import org.springframework.util.AntPathMatcher;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
/**
* RocketMQ log collect ConfigUtils.
@@ -33,32 +31,9 @@ public final class RocketLogCollectConfigUtils {
private static Map<String, String> apiTopicMap = new HashMap<>();
- private static LogCollectConfig.GlobalLogConfig globalLogConfig;
-
- private static final LogCollectConfig.GlobalLogConfig
DEFAULT_GLOBAL_LOG_CONFIG =
- new LogCollectConfig.GlobalLogConfig();
-
public RocketLogCollectConfigUtils() {
}
- /**
- * set global config.
- *
- * @param config global config
- */
- public static void setGlobalConfig(final LogCollectConfig.GlobalLogConfig
config) {
- globalLogConfig = config;
- }
-
- /**
- * get global config.
- *
- * @return {@linkplain LogCollectConfig.GlobalLogConfig}
- */
- public static LogCollectConfig.GlobalLogConfig getGlobalLogConfig() {
- return
Optional.ofNullable(globalLogConfig).orElse(DEFAULT_GLOBAL_LOG_CONFIG);
- }
-
/**
* set api topic map.
* @param uriTopicMap api topic map
diff --git
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/test/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClientTest.java
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/test/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClientTest.java
index ca6684ef2..5cda85f1e 100644
---
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/test/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClientTest.java
+++
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-rocketmq/src/test/java/org/apache/shenyu/plugin/logging/rocketmq/client/RocketMQLogCollectClientTest.java
@@ -22,7 +22,6 @@ import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog;
import org.apache.shenyu.plugin.logging.rocketmq.config.LogCollectConfig;
import org.apache.shenyu.plugin.logging.rocketmq.constant.LoggingConstant;
-import
org.apache.shenyu.plugin.logging.rocketmq.utils.RocketLogCollectConfigUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -67,7 +66,7 @@ public class RocketMQLogCollectClientTest {
@Test
public void testConsume() {
String msg = "";
- RocketLogCollectConfigUtils.setGlobalConfig(globalLogConfig);
+ LogCollectConfig.INSTANCE.setGlobalLogConfig(globalLogConfig);
rocketMQLogCollectClient.initProducer(properties);
try {
rocketMQLogCollectClient.consume(logs);
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-logging-aliyun-sls/pom.xml
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-logging-aliyun-sls/pom.xml
index 35d751d75..4ccd318ee 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-logging-aliyun-sls/pom.xml
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-logging-aliyun-sls/pom.xml
@@ -28,11 +28,6 @@
<artifactId>shenyu-spring-boot-starter-plugin-logging-aliyun-sls</artifactId>
- <properties>
- <maven.compiler.source>8</maven.compiler.source>
- <maven.compiler.target>8</maven.compiler.target>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.apache.shenyu</groupId>