This is an automated email from the ASF dual-hosted git repository.

liuhongyu pushed a commit to branch feat/refactor
in repository https://gitbox.apache.org/repos/asf/shenyu.git

commit 17ab4cb154063f0c959f6395a881aa8d4eafe540
Author: liuhy <[email protected]>
AuthorDate: Thu Jan 8 16:22:18 2026 +0800

    refactor: streamline logging in Shenyu plugin lifecycle methods
---
 shenyu-bootstrap/src/main/resources/application.yml   |  2 +-
 .../org/apache/shenyu/plugin/api/ShenyuPlugin.java    | 16 ++++++----------
 .../apache/shenyu/web/handler/ShenyuWebHandler.java   | 19 ++++++++-----------
 3 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/shenyu-bootstrap/src/main/resources/application.yml 
b/shenyu-bootstrap/src/main/resources/application.yml
index 2a52beee8c..1bc92b6fd3 100644
--- a/shenyu-bootstrap/src/main/resources/application.yml
+++ b/shenyu-bootstrap/src/main/resources/application.yml
@@ -108,7 +108,7 @@ shenyu:
       # set to false, user can custom the netty tcp server config.
       webServerFactoryEnabled: true
       selectCount: 1
-      # workerCount: 8
+      workerCount: 8
       accessLog: false
       serverSocketChannel:
         soBackLog: 128
diff --git 
a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/ShenyuPlugin.java
 
b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/ShenyuPlugin.java
index e96b65e48b..6fef76e8f1 100644
--- 
a/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/ShenyuPlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/ShenyuPlugin.java
@@ -138,9 +138,7 @@ public interface ShenyuPlugin {
      * @param exchange context
      */
     default void before(ServerWebExchange exchange) {
-        if (LOG.isDebugEnabled()) {
-            exchange.getAttributes().put(Constants.PLUGIN_START_TIME + 
named(), System.currentTimeMillis());
-        }
+        exchange.getAttributes().put(Constants.PLUGIN_START_TIME + named(), 
System.currentTimeMillis());
     }
 
     /**
@@ -149,13 +147,11 @@ public interface ShenyuPlugin {
      * @param exchange context
      */
     default void after(ServerWebExchange exchange) {
-        if (LOG.isDebugEnabled()) {
-            long currentTimeMillis = System.currentTimeMillis();
-            Object startTime = 
exchange.getAttributes().get(Constants.PLUGIN_START_TIME + named());
-            if (Objects.nonNull(startTime)) {
-                LOG.debug("shenyu traceId:{}, plugin named:{}, cost:{}", 
exchange.getLogPrefix(), named(), currentTimeMillis - (long) startTime);
-                exchange.getAttributes().remove(Constants.PLUGIN_START_TIME + 
named());
-            }
+        long currentTimeMillis = System.currentTimeMillis();
+        Object startTime = 
exchange.getAttributes().get(Constants.PLUGIN_START_TIME + named());
+        if (Objects.nonNull(startTime)) {
+            LOG.debug("shenyu traceId:{}, plugin named:{}, cost:{}", 
exchange.getLogPrefix(), named(), currentTimeMillis - (long) startTime);
+            exchange.getAttributes().remove(Constants.PLUGIN_START_TIME + 
named());
         }
     }
 }
diff --git 
a/shenyu-web/src/main/java/org/apache/shenyu/web/handler/ShenyuWebHandler.java 
b/shenyu-web/src/main/java/org/apache/shenyu/web/handler/ShenyuWebHandler.java
index 2ac3fb22fa..460d113f92 100644
--- 
a/shenyu-web/src/main/java/org/apache/shenyu/web/handler/ShenyuWebHandler.java
+++ 
b/shenyu-web/src/main/java/org/apache/shenyu/web/handler/ShenyuWebHandler.java
@@ -121,19 +121,16 @@ public final class ShenyuWebHandler implements 
WebHandler, ApplicationListener<P
      */
     @Override
     public Mono<Void> handle(@NonNull final ServerWebExchange exchange) {
-        Mono<Void> execute = Mono.defer(() -> {
-            if (LOG.isDebugEnabled()) {
-                before(exchange);
+        try {
+            before(exchange);
+            Mono<Void> execute = new 
DefaultShenyuPluginChain(plugins).execute(exchange);
+            if (scheduled) {
+                return execute.subscribeOn(scheduler);
             }
-            return new DefaultShenyuPluginChain(plugins).execute(exchange);
-        });
-        if (scheduled) {
-            execute = execute.subscribeOn(scheduler);
-        }
-        if (LOG.isDebugEnabled()) {
-            execute = execute.doFinally(s -> after(exchange));
+            return execute;
+        } finally {
+            after(exchange);
         }
-        return execute;
     }
     
     /**

Reply via email to