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

pkarwasz 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 76499ceac5 Fix location requirements in `RewriteAppender`
76499ceac5 is described below

commit 76499ceac530fcc4082ff2480b0ebafd25d39de5
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Mon Feb 13 21:15:18 2023 +0100

    Fix location requirements in `RewriteAppender`
    
    `RewriteAppender` did not correctly compute if it requires location
    information. This closes #1274.
---
 .../core/appender/rewrite/RewriteAppender.java     | 13 ++++++++++
 .../1274_fix_RewriteAppender_requiresLocation.xml  | 28 ++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
index fc7dc5e664..524a492317 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
@@ -33,6 +33,7 @@ import 
org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.impl.LocationAware;
 import org.apache.logging.log4j.core.util.Booleans;
 
 /**
@@ -116,4 +117,16 @@ public final class RewriteAppender extends 
AbstractAppender {
         }
         return new RewriteAppender(name, filter, ignoreExceptions, 
appenderRefs, rewritePolicy, config, null);
     }
+
+    @Override
+    public boolean requiresLocation() {
+        for (final AppenderControl control : appenders.values()) {
+            final Appender appender = control.getAppender();
+            if (appender instanceof LocationAware && ((LocationAware) 
appender).requiresLocation()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }
diff --git a/src/changelog/.2.x.x/1274_fix_RewriteAppender_requiresLocation.xml 
b/src/changelog/.2.x.x/1274_fix_RewriteAppender_requiresLocation.xml
new file mode 100644
index 0000000000..addc434e93
--- /dev/null
+++ b/src/changelog/.2.x.x/1274_fix_RewriteAppender_requiresLocation.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="http://logging.apache.org/log4j/changelog";
+       xsi:schemaLocation="http://logging.apache.org/log4j/changelog 
https://logging.apache.org/log4j/changelog-0.1.0.xsd";
+       type="fixed">
+  <issue id="1274" link="https://github.com/apache/logging-log4j2/pull/1274"/>
+  <author id="amirhadadi"/>
+  <author id="pkarwasz"/>
+  <description format="asciidoc">
+    Fix detection of location requirements in `RewriteAppender`.
+  </description>
+</entry>

Reply via email to