pandaapo commented on issue #4697:
URL: https://github.com/apache/eventmesh/issues/4697#issuecomment-1872905020
> So, to replace some of the following writing:
>
> ```java
> if (log.isDebugEnabled()) {
> log.debug("A time-consuming method: {}", myMethod());
> }
> ```
>
> we now have three options:
>
> * Continue using Slf4j
>
> * use Fluent Logging API
>
> ```java
> log.atDebug().setMessage("A time-consuming method: {}").addArgument(()
-> myMethod()).log();
> ```
>
>
>
>
>
>
>
>
>
>
>
> ```java
> log.atDebug().addArgument(() -> myMethod()).log("A time-consuming
method: {}");
> ```
>
>
>
>
>
>
>
>
>
>
>
> Pro: able to remove LogUtils
> Con: not concise; no much value in learning it
>
> * encapsulate Fluent Logging API in LogUtils
>
> ```java
> LogUtil.debug(log, "A time-consuming method: {}", () -> myMethod());
> ```
>
>
>
>
>
>
>
>
>
>
>
> Pro: able to support customized usage such as adding a Throwable behind
suppliers: `LogUtil.debug(log, "A time-consuming method: {}", () -> myMethod(),
e);`
> Con: not the native usage
> * Use `@Log4j2` instead of `@Slf4j`
>
> ```java
> log.debug("A time-consuming method: {}", () -> myMethod());
> ```
>
> Pro: concise; able to remove LogUtils; we are using `log4j2.xml` as
config, so the logs printed in the console won't change
>
> Con: If one day we no longer use Log4j2, there may be a need to switch to
a different logging artifact.
>
> Which one of these three options is not bad, but for the developer's
habit, the writing of "Use `@Log4j2` instead of `@Slf4j`" may be the best;
however, if there is resistance to migrating the logging API, we can choose to
"encapsulate Fluent Logging API in LogUtils."
>
> @pandaapo Which one do you prefer?
@Pil0tXia,
@ppkarwasz prefers to use a purer Log4j API. You prefer to use encapsulated
LogUtils that contains Fluent Logging API (SLF4J). I prefer to use SLF4J's
native API.
As you said "these three options are not bad", so I sincerely believe that
there is still a need for another reviewer to express views on these options.
--
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]