Pil0tXia commented on code in PR #4698:
URL: https://github.com/apache/eventmesh/pull/4698#discussion_r1438503329


##########
eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/codec/Codec.java:
##########
@@ -161,7 +159,7 @@ private Header parseHeader(ByteBuf in, int headerLength) 
throws JsonProcessingEx
             }
             final byte[] headerData = new byte[headerLength];
             in.readBytes(headerData);
-            LogUtils.debug(log, "Decode headerJson={}", 
deserializeBytes(headerData));
+            log.atDebug().log("Decode headerJson={}", 
deserializeBytes(headerData));

Review Comment:
   True🤣I tested it with the code below, and the timer shows that only Supplier 
could avoid executing `formatMsg()`. However the Fluent API said that `For 
disabled log levels, the returned LoggingEventBuilder instance does nothing`. 
Why is that?
   
   Test code, ran under `debug` level:
   
   ```
           ......
           long traceStart = System.currentTimeMillis();
           log.trace("log.trace(). formatMsg() return value: {}", 
formatMsg("log.trace()", "executed"));
           long traceEnd = System.currentTimeMillis();
           long atTraceStart = System.currentTimeMillis();
           log.atTrace().log("log.atTrace().log(). formatMsg() return value: 
{}", formatMsg("log.atTrace().log()", "executed"));
           long atTraceEnd = System.currentTimeMillis();
           long atTraceSupplierStart = System.currentTimeMillis();
           log.atTrace().addArgument(() -> formatMsg("log.atTrace() Supplier", 
"executed")).log("log.atTrace().addArgument().log()");
           long atTraceSupplierEnd = System.currentTimeMillis();
           log.info("log.trace() cost: {}ms, log.atTrace().log() cost: {}ms, 
log.atTrace() Supplier cost: {}ms",
                   traceEnd - traceStart, atTraceEnd - atTraceStart, 
atTraceSupplierEnd - atTraceSupplierStart);
       }
   
       private String formatMsg(String name, String status) {
           try {
               Thread.sleep(1000);
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }
           return name + "-" + status;
       }
   ```
   
   Output:
   
   ```
   log.trace() cost: 1009ms, log.atTrace().log() cost: 1002ms, log.atTrace() 
Supplier cost: 0ms
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to