Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Enhancement] Use Fluent Logging API to provide accurate, concise, and elegant logging #4697

@Pil0tXia

Description

@Pil0tXia

Search before asking

  • I had searched in the issues and found no similar issues.

Enhancement Request

This issue is a sub-task of #4681.

The purpose of this issue is to provide syntactic support for resolving the logging problem #4681 by upgrading the versions of log4j and slf4j.

Background Knowledge

Disscussion: apache/logging-log4j2#2133

The additional isDebugEnabled() check before log.debug() is performed in order to avoid invoking the methods referenced in the message field, thus improving logging performance. For example:

log.debug("formatted msg: {}", formatMsg(rawMsg));

Even when the log level is set to info, the formatMsg(rawMsg) method will still be called and return a result before being passed as an argument to log.debug(). This takes time.

Describe the solution you'd like

Solution Selection

Since slf4j does not support passing arguments through the Supplier introduced in log4j 2.13.0 (discussed in qos-ch/slf4j#70, no need to read though), we will not adopt the solution of lazy invocation by passing the Supplier parameter. Additionally, the usage of the Supplier appears redundant, and most contributors cannot understand the difference between using a Supplier or not without prior knowledge.

The Fluent Logging API since slf4j 2.0.0 provides a more elegant and space-saving way of writing code. The modifications to the WatchFileManager class demonstrate the recommended approach.

image

Scenarios where Fluent Logging API is unnecessary

Only the scenario mentioned in the Background Knowledge section require the use of Fluent Logging API. For example, in the case of the changes in Codec class L224, where no object parameters are passed or existing objects are referenced, there is no additional performance overhead, and there is no need to pre-evaluate log levels. The simplest usage of slf4j can be directly applied.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions