You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2014/07/16 15:38:47 UTC

svn commit: r1611007 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java src/changes/changes.xml

Author: rpopma
Date: Wed Jul 16 13:38:46 2014
New Revision: 1611007

URL: http://svn.apache.org/r1611007
Log:
LOG4J2-719 Correctly handle NetworkOnMainThreadException thrown on Android during Log4j2 initialization

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=1611007&r1=1611006&r2=1611007&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java Wed Jul 16 13:38:46 2014
@@ -354,7 +354,13 @@ public class LoggerContext extends Abstr
         final Configuration prev = this.config;
         config.addListener(this);
         final ConcurrentMap<String, String> map = config.getComponent(Configuration.CONTEXT_PROPERTIES);
-        map.putIfAbsent("hostName", NetUtils.getLocalHostname());
+        
+        try { // LOG4J2-719 network access may throw android.os.NetworkOnMainThreadException
+            map.putIfAbsent("hostName", NetUtils.getLocalHostname());
+        } catch (Exception ex) {
+            LOGGER.debug("Ignoring {}, setting hostName to 'unknown'", ex.toString());
+            map.putIfAbsent("hostName", "unknown");
+        }
         map.putIfAbsent("contextName", name);
         config.start();
         this.config = config;

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1611007&r1=1611006&r2=1611007&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Jul 16 13:38:46 2014
@@ -22,6 +22,9 @@
   </properties>
   <body>
     <release version="?" date="2014-mm-dd" description="?">
+      <action issue="LOG4J2-719" dev="popmarem" type="fix">
+        Correctly handle NetworkOnMainThreadException thrown on Android during Log4j2 initialization.
+      </action>
       <action issue="LOG4J2-716" dev="popmarem" type="fix">
         Automatically disable log4j JMX when detecting we are running on Android.
       </action>