This is an automated email from the ASF dual-hosted git repository.
hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 21d6409b90 Added support for enabling debug logs for okhttp (#4976)
21d6409b90 is described below
commit 21d6409b90634dab6b508915fc31cf35c62ecd9a
Author: Kerwin Bryant <[email protected]>
AuthorDate: Sat Aug 19 22:00:33 2023 +0800
Added support for enabling debug logs for okhttp (#4976)
* Added support for enabling debug logs for okhttp
* Create LICENSE-logging-interceptor.txt
* Complete the modification suggestions proposed by @moremind
---------
Co-authored-by: moremind <[email protected]>
---
shenyu-admin/pom.xml | 5 +++++
.../src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java | 9 +++++++++
shenyu-admin/src/main/resources/application.yml | 1 +
shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE | 1 +
4 files changed, 16 insertions(+)
diff --git a/shenyu-admin/pom.xml b/shenyu-admin/pom.xml
index f21b6cbf2b..3fca6a4bec 100644
--- a/shenyu-admin/pom.xml
+++ b/shenyu-admin/pom.xml
@@ -286,6 +286,11 @@
<artifactId>okhttp</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>logging-interceptor</artifactId>
+ </dependency>
+
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
index a05ba534a8..56ffe68b52 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/HttpUtils.java
@@ -28,6 +28,8 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
+import okhttp3.logging.HttpLoggingInterceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shenyu.common.utils.JsonUtils;
import org.slf4j.Logger;
@@ -156,7 +158,14 @@ public class HttpUtils {
}
protected void initHttpClient(final HttpToolConfig httpToolConfig) {
+ HttpLoggingInterceptor httpLoggingInterceptor = new
HttpLoggingInterceptor(s -> {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(s);
+ }
+ });
+ httpLoggingInterceptor.setLevel(Level.BODY);
httpClient = new OkHttpClient.Builder()
+ .addInterceptor(httpLoggingInterceptor)
.connectTimeout(httpToolConfig.connectTimeoutSeconds,
TimeUnit.SECONDS)
.readTimeout(httpToolConfig.readTimeoutSeconds, TimeUnit.SECONDS)
.writeTimeout(httpToolConfig.writeTimeoutSeconds, TimeUnit.SECONDS)
diff --git a/shenyu-admin/src/main/resources/application.yml
b/shenyu-admin/src/main/resources/application.yml
index 61cd710a13..74ffca92e8 100755
--- a/shenyu-admin/src/main/resources/application.yml
+++ b/shenyu-admin/src/main/resources/application.yml
@@ -150,3 +150,4 @@ logging:
org.apache.shenyu.bonuspoint: info
org.apache.shenyu.lottery: info
org.apache.shenyu: info
+# org.apache.shenyu.admin.utils.HttpUtils: debug
diff --git a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
index df6f837cf0..238133bbed 100644
--- a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
+++ b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
@@ -272,6 +272,7 @@ The text of each license is the standard Apache 2.0 license.
listenablefuture 9999.0-empty-to-avoid-conflict-with-guava:
https://github.com/google/guava, Apache 2.0
log4j-api 2.17.2: https://logging.apache.org/log4j/2.x/log4j-api, Apache
2.0
log4j-to-slf4j 2.17.2:
https://logging.apache.org/log4j/2.x/log4j-to-slf4j, Apache 2.0
+ logging-interceptor 4.9.3: https://github.com/square/okhttp, Apache 2.0
mapstruct 1.2.0.Final: https://github.com/mapstruct/mapstruct, Apache 2.0
micrometer-core 1.9.12: https://github.com/micrometer-metrics/micrometer,
Apache 2.0
micrometer-registry-prometheus 1.9.12:
https://github.com/micrometer-metrics/micrometer, Apache 2.0