Louis Bergelson created LOG4J2-3602: ---------------------------------------
Summary: Don't output ERROR level stacktrace in getLogger() call when there is no network available Key: LOG4J2-3602 URL: https://issues.apache.org/jira/browse/LOG4J2-3602 Project: Log4j 2 Issue Type: Improvement Components: Core Affects Versions: 2.17.2, 2.17.1 Environment: In this case software was running in a docker container with localhost `–network none` set. Reporter: Louis Bergelson 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: {quote}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 {quote} 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");}} {{}}} -- This message was sent by Atlassian Jira (v8.20.10#820010)