Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3602

Don't output ERROR level stacktrace in getLogger() call when there is no network available

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Trivial
    • Resolution: Unresolved
    • 2.17.1, 2.17.2
    • None
    • Core
    • None
    • In this case software was running in a docker container with localhost `–network none` set.  

    Description

      If there is no network adaptor trying to get a new logger using `LogManager.getLogger()` results in an ERROR level log message with a full stacktrace. This seems unintentional and undesirable.

      Here's an example of the output:

      ERROR Could not determine local host name java.net.UnknownHostException: de2c81c88ddc: de2c81c88ddc: Temporary failure in name resolution
      at java.net.InetAddress.getLocalHost(InetAddress.java:1506)
      at org.apache.logging.log4j.core.util.NetUtils.getLocalHostname(NetUtils.java:54)
      at org.apache.logging.log4j.core.LoggerContext.lambda$setConfiguration$0(LoggerContext.java:620)
      at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
      at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:620)
      at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:699)
      at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
      at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
      at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
      at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
      at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
      at org.broadinstitute.hellbender.utils.Utils.<clinit>(Utils.java:72)
      at org.broadinstitute.hellbender.Main.<clinit>(Main.java:45)
      Caused by: java.net.UnknownHostException: de2c81c88ddc: Temporary failure in name resolution
      at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
      at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
      at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
      at java.net.InetAddress.getLocalHost(InetAddress.java:1501)
      ...13 more

       

       I believe this is unintentional because the associated code has a general catch for all potential exceptions which logs a DEBUG level message in case of failure.  However the call to `NetUtils.getLocalHostname()` actually does it's own error handling and very verbose logging.

       

      The relevant call is here at LoggerContext.java line 613

      try {
          map.computeIfAbsent("hostName", s -> NetUtils.getLocalHostname());
      } catch (final Exception ex) {
          LOGGER.debug("Ignoring {}, setting hostName to 'unknown'", ex.toString());
          map.putIfAbsent("hostName", "unknown");
      }

       

      The problematic logging statement is in NetUtils.getLocalHostname() line 77:

       

      } catch (final UnknownHostException uhe) {

        ...

         LOGGER.error("Could not determine local host name", uhe);
         return UNKNOWN_LOCALHOST;
      }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              louisb@broadinstitute.org Louis Bergelson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: