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

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c2997a01d LOG4J2-3491 - Correctly default to not include location 
info for AsyncLoggers
0c2997a01d is described below

commit 0c2997a01d088484b2178fbcf2075e93f54fab76
Author: Ralph Goers <[email protected]>
AuthorDate: Wed May 18 14:41:33 2022 -0700

    LOG4J2-3491 - Correctly default to not include location info for 
AsyncLoggers
---
 .../core/async/AsyncLoggerDefaultLocationTest.java | 71 ++++++++++++++++++++++
 .../resources/AsyncLoggerDefaultLocationTest.xml   | 20 ++++++
 .../log4j/core/async/AsyncLoggerConfig.java        |  6 +-
 src/changes/changes.xml                            |  3 +
 4 files changed, 97 insertions(+), 3 deletions(-)

diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java
new file mode 100644
index 0000000000..ac44aa5a71
--- /dev/null
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.async;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.test.appender.ListAppender;
+import org.apache.logging.log4j.core.test.categories.AsyncLoggers;
+import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.util.Strings;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+@Category(AsyncLoggers.class)
+public class AsyncLoggerDefaultLocationTest {
+
+    @BeforeClass
+    public static void beforeClass() {
+        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
+                "AsyncLoggerDefaultLocationTest.xml");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, Strings.EMPTY);
+    }
+
+    @Test
+    public void testAsyncLogWritesToLog() throws Exception {
+        LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        ListAppender app = context.getConfiguration().getAppender("List");
+        assertNotNull(app);
+        final Logger log = context.getLogger("com.foo.Bar");
+        final String msg = "Async logger msg with no location by default";
+        log.info(msg);
+        context.stop();
+        assertEquals(1, app.getEvents().size());
+        LogEvent event = app.getEvents().get(0);
+        assertFalse("includeLocation should be false", 
event.isIncludeLocation());
+        assertNull("Location data should not be present", event.getSource());
+    }
+
+}
diff --git 
a/log4j-core-test/src/test/resources/AsyncLoggerDefaultLocationTest.xml 
b/log4j-core-test/src/test/resources/AsyncLoggerDefaultLocationTest.xml
new file mode 100644
index 0000000000..f5a3cb3231
--- /dev/null
+++ b/log4j-core-test/src/test/resources/AsyncLoggerDefaultLocationTest.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="OFF">
+  <Appenders>
+    <List name="List"/>
+    <Console name="Console" target="SYSTEM_OUT">
+      <PatternLayout>
+        <pattern>%d %p %c{1.} [%t] %X{aKey} %m %ex%n</pattern>
+      </PatternLayout>
+    </Console>
+  </Appenders>
+  
+  <Loggers>
+    <AsyncLogger name="com.foo.Bar" level="trace" additivity="false">
+      <AppenderRef ref="List"/>
+    </AsyncLogger>
+    <Root level="info">
+      <AppenderRef ref="Console"/>
+    </Root>
+  </Loggers>
+</Configuration>
\ No newline at end of file
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
index 49d24fe5cc..2bf780bd27 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
@@ -86,7 +86,7 @@ public class AsyncLoggerConfig extends LoggerConfig {
             LevelAndRefs container = LoggerConfig.getLevelAndRefs(getLevel(), 
getRefs(), getLevelAndRefs(),
                     getConfig());
             return new AsyncLoggerConfig(name, container.refs,getFilter(), 
container.level, isAdditivity(),
-                    getProperties(), getConfig(), 
includeLocation(getIncludeLocation(), getConfig()), getLogEventFactory());
+                    getProperties(), getConfig(), 
includeLocation(getIncludeLocation()), getLogEventFactory());
         }
     }
 
@@ -307,8 +307,8 @@ public class AsyncLoggerConfig extends LoggerConfig {
                 LevelAndRefs container = 
LoggerConfig.getLevelAndRefs(getLevel(), getRefs(), getLevelAndRefs(),
                         getConfig());
                 return new AsyncLoggerConfig(LogManager.ROOT_LOGGER_NAME, 
container.refs, getFilter(), container.level,
-                        isAdditivity(), getProperties(), getConfig(), 
includeLocation(getIncludeLocation(),
-                        getConfig()), getLogEventFactory());
+                        isAdditivity(), getProperties(), getConfig(),
+                        
AsyncLoggerConfig.includeLocation(getIncludeLocation()), getLogEventFactory());
             }
         }
 
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ae81982393..96c9da3082 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -199,6 +199,9 @@
       </action>
     </release>
     <release version="2.18.0" date="20YY-MM-DD" description="GA Release 
2.17.3">
+      <action issue="LOG4J2-3491" dev="rgoers" type="fix" due-to="Avihai 
Marchiano">
+        Async Loggers were including the location information by default.
+      </action>
       <action issue="LOG4J2-3506" dev="rgoers" type="update">
         Support Spring 2.6.x.
       </action>

Reply via email to