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


##########
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?
   
   This is due to the order in which Java evaluates methods: it always 
evaluates the arguments of a method before the method itself. In this concrete 
example:
   
   ```java
   log.atDebug().log("Decode headerJson={}", deserializeBytes(headerData));
   ```
   
   Java will:
   
   1. Call `Logger#atDebug()` and obtain a `NOPLoggingEventBuilder`,
   2. Call `deserializeBytes` and obtain a string,
   3. Call `NOPLoggingEventBuilder#log` which does nothing.
   
   The [Scala 
language](https://docs.scala-lang.org/tour/by-name-parameters.html) has 
call-by-name arguments that are evaluated only if they are used. In Java 
everything is call-by-value and the arguments are computed even if they are not 
used.



-- 
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