Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-7866

Improvements to the logging API usage (technical debt)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.0-alpha-2
    • 4.0.0-alpha-8, 4.0.0
    • Core
    • None

    Description

      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 :

       

                  logger.debug("Toolchains configuration was not found at " + userToolchainsFile);
      

      can be replaced with :

                  logger.debug("Toolchains configuration was not found at {}", userToolchainsFile);
      • 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 :

       

                      } else {
                          Lifecycle original = phaseToLifecycleMap.get(phase);
                          logger.warn("Duplicated lifecycle phase " + phase + ". Defined in " + original.getId()
                                  + " but also in " + lifecycle.getId());
                      }
      

      can be replaced with the following code to avoid the cost of the map lookup :

       

                      } else if (logger.isWarnEnabled()) {
                          Lifecycle original = phaseToLifecycleMap.get(phase);
                          logger.warn(
                                  "Duplicated lifecycle phase {}. Defined in {} but also in {}",
                                  phase,
                                  original.getId(),
                                  lifecycle.getId());
                      }
      
      • Remove some unneeded conditional guarding to avoid testing twice if the log level is enabled, like for example :

       

                  if (logger.isDebugEnabled()) {
                      logger.debug("Lifecycle " + lifecycle);
                  }
      

      can be replaced with :

                  logger.debug("Lifecycle {}", lifecycle);

      Attachments

        Issue Links

          Activity

            People

              gnodet Guillaume Nodet
              sebastiend sebastien
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: