[
https://issues.apache.org/jira/browse/MNG-7866?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Guillaume Nodet closed MNG-7866.
--------------------------------
Assignee: Guillaume Nodet
Resolution: Fixed
> Improvements to the logging API usage (technical debt)
> ------------------------------------------------------
>
> Key: MNG-7866
> URL: https://issues.apache.org/jira/browse/MNG-7866
> Project: Maven
> Issue Type: Improvement
> Components: Core
> Affects Versions: 4.0.0-alpha-2
> Reporter: sebastien
> Assignee: Guillaume Nodet
> Priority: Minor
> Fix For: 4.0.0-alpha-8
>
>
> Since maven 4 is now using the Slf4J logger API, some logging code can be
> improved.
> Typical improvements are:
> * Use message formats with placeholders to avoid premature formatting and
> avoid the unnecessary garbage when then log level is disabled. Example :
>
> {code:java}
> logger.debug("Toolchains configuration was not found at " +
> userToolchainsFile);
> {code}
> can be replaced with :
> {code:java}
> logger.debug("Toolchains configuration was not found at {}",
> userToolchainsFile);{code}
> * Guarding some logging statements with conditionals on isXXXXEnabled() to
> avoid unnecessary garbage when then log level is disabled. Useful when some
> formatting must be done outside the logger call. Example :
>
> {code:java}
> } else {
> Lifecycle original = phaseToLifecycleMap.get(phase);
> logger.warn("Duplicated lifecycle phase " + phase + ".
> Defined in " + original.getId()
> + " but also in " + lifecycle.getId());
> }
> {code}
> can be replaced with the following code to avoid the cost of the map lookup :
>
> {code:java}
> } else if (logger.isWarnEnabled()) {
> Lifecycle original = phaseToLifecycleMap.get(phase);
> logger.warn(
> "Duplicated lifecycle phase {}. Defined in {} but
> also in {}",
> phase,
> original.getId(),
> lifecycle.getId());
> }
> {code}
> * Remove some unneeded conditional guarding to avoid testing twice if the
> log level is enabled, like for example :
>
> {code:java}
> if (logger.isDebugEnabled()) {
> logger.debug("Lifecycle " + lifecycle);
> }
> {code}
> can be replaced with :
> {code:java}
> logger.debug("Lifecycle {}", lifecycle);{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)