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

rgoers 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 26c7c42e83 LOG4J2-3491 - Correctly default to not include location 
info for AsyncLoggers
26c7c42e83 is described below

commit 26c7c42e8343c84971a64de66bca47392088259b
Author: Ralph Goers <[email protected]>
AuthorDate: Wed May 18 14:41:19 2022 -0700

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

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 4c37a74ade..6fdca02336 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
@@ -85,7 +85,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()));
+                    getProperties(), getConfig(), 
includeLocation(getIncludeLocation()));
         }
     }
 
@@ -319,8 +319,7 @@ 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()));
+                        isAdditivity(), getProperties(), getConfig(), 
includeLocation(getIncludeLocation()));
             }
         }
 
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
index cb76aed4ea..5886e67de6 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
@@ -752,9 +752,7 @@ public class LoggerConfig extends AbstractFilterable 
implements LocationAware {
     }
 
     /**
-     * @deprecated Please use {@link #includeLocation(String, Configuration)}
      */
-    @Deprecated
     protected static boolean includeLocation(final String 
includeLocationConfigValue) {
         return includeLocation(includeLocationConfigValue, null);
     }
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java
new file mode 100644
index 0000000000..29b689021a
--- /dev/null
+++ 
b/log4j-core/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.categories.AsyncLoggers;
+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.util.Constants;
+import org.apache.logging.log4j.test.appender.ListAppender;
+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/src/test/resources/AsyncLoggerDefaultLocationTest.xml 
b/log4j-core/src/test/resources/AsyncLoggerDefaultLocationTest.xml
new file mode 100644
index 0000000000..f5a3cb3231
--- /dev/null
+++ b/log4j-core/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/src/changes/changes.xml b/src/changes/changes.xml
index 6c83d6439e..8c9dea221f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -30,7 +30,9 @@
          - "remove" - Removed
     -->
     <release version="2.18.0" date="2022-TBD" description="GA Release 2.18.0">
-      <!-- FIXES -->
+      <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-1376" dev="mneundorfer" type="fix">
         Allow enterprise id to be an OID fragment.
       </action>

Reply via email to