You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ck...@apache.org on 2021/08/30 01:43:51 UTC

[logging-log4j2] branch release-2.x updated: LOG4J2-2808 Don't look up localhost if hostName is already configured

This is an automated email from the ASF dual-hosted git repository.

ckozak pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/release-2.x by this push:
     new 177a857  LOG4J2-2808 Don't look up localhost if hostName is already configured
177a857 is described below

commit 177a85708535cad6a3e0af9468f323135cc91fbd
Author: Asapha <gi...@asapha.me>
AuthorDate: Sun Aug 22 17:41:35 2021 +0200

    LOG4J2-2808 Don't look up localhost if hostName is already configured
---
 .../src/main/java/org/apache/logging/log4j/core/LoggerContext.java     | 3 ++-
 src/changes/changes.xml                                                | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index 5e11e0c..6054e34 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -616,7 +616,8 @@ public class LoggerContext extends AbstractLifeCycle
             final ConcurrentMap<String, String> map = config.getComponent(Configuration.CONTEXT_PROPERTIES);
 
             try { // LOG4J2-719 network access may throw android.os.NetworkOnMainThreadException
-                map.putIfAbsent("hostName", NetUtils.getLocalHostname());
+                // LOG4J2-2808 don't block unless necessary
+                map.computeIfAbsent("hostName", s -> NetUtils.getLocalHostname());
             } catch (final Exception ex) {
                 LOGGER.debug("Ignoring {}, setting hostName to 'unknown'", ex.toString());
                 map.putIfAbsent("hostName", "unknown");
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cace367..2e7ce39 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -95,6 +95,9 @@
 	based on performance improvements in modern Java releases.
       </action>
       <!-- FIXES -->
+      <action issue="LOG4J2-2808" dev="ckozak" type="fix" due-to="Asapha Halifa">
+        LoggerContext skips resolving localhost when hostName is configured.
+      </action>
       <action issue="LOG4J2-3150" dev="ckozak" type="fix">
         RandomAccessFile appender uses the correct default buffer size of 256 kB
         rather than the default appender buffer size of 8 kB.