File tree Expand file tree Collapse file tree 4 files changed +69
-0
lines changed
java/org/apache/logging/log4j/core/appender
log4j-core/src/main/java/org/apache/logging/log4j/core/appender Expand file tree Collapse file tree 4 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -173,4 +173,11 @@ public void testShutdownTimeout(final LoggerContext context) {
173173 context .getLogger ("Logger" ).info ("This is a test" );
174174 context .stop ();
175175 }
176+
177+ @ Test
178+ @ LoggerContextSource ("log4j-asynch-location.xml" )
179+ public void testRequiresLocation (final LoggerContext context ) {
180+ final AsyncAppender appender = context .getConfiguration ().getAppender ("Async" );
181+ assertTrue (appender .requiresLocation ());
182+ }
176183}
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <!--
3+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
4+ ~ contributor license agreements. See the NOTICE file distributed with
5+ ~ this work for additional information regarding copyright ownership.
6+ ~ The ASF licenses this file to you under the Apache License, Version 2.0
7+ ~ (the "License"); you may not use this file except in compliance with
8+ ~ the License. You may obtain a copy of the License at
9+ ~
10+ ~ http://www.apache.org/licenses/LICENSE-2.0
11+ ~
12+ ~ Unless required by applicable law or agreed to in writing, software
13+ ~ distributed under the License is distributed on an "AS IS" BASIS,
14+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ ~ See the License for the specific language governing permissions and
16+ ~ limitations under the License.
17+ -->
18+ <Configuration status =" OFF" >
19+
20+ <Appenders >
21+ <Console name =" STDOUT" >
22+ <PatternLayout pattern =" %m%L%n" />
23+ </Console >
24+ <Async name =" Async" includeLocation =" true" >
25+ <AppenderRef ref =" STDOUT" />
26+ </Async >
27+ </Appenders >
28+
29+ <Loggers >
30+ <Root level =" debug" includeLocation =" true" >
31+ <AppenderRef ref =" Async" />
32+ </Root >
33+ </Loggers >
34+
35+ </Configuration >
Original file line number Diff line number Diff line change 4747import org .apache .logging .log4j .core .config .plugins .PluginElement ;
4848import org .apache .logging .log4j .core .config .plugins .validation .constraints .Required ;
4949import org .apache .logging .log4j .core .filter .AbstractFilterable ;
50+ import org .apache .logging .log4j .core .impl .LocationAware ;
5051import org .apache .logging .log4j .core .impl .Log4jLogEvent ;
5152import org .apache .logging .log4j .spi .AbstractLogger ;
5253
@@ -471,4 +472,22 @@ public int getQueueRemainingCapacity() {
471472 public int getQueueSize () {
472473 return queue .size ();
473474 }
475+
476+ @ Override
477+ public boolean requiresLocation () {
478+ if (!includeLocation ) {
479+ return false ;
480+ }
481+ for (final Appender appender : this .getAppenders ()) {
482+ if (appender instanceof LocationAware && ((LocationAware ) appender ).requiresLocation ()) {
483+ return true ;
484+ }
485+ }
486+ if (errorAppender != null
487+ && errorAppender .getAppender () instanceof LocationAware
488+ && ((LocationAware ) errorAppender .getAppender ()).requiresLocation ()) {
489+ return true ;
490+ }
491+ return false ;
492+ }
474493}
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <entry xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xmlns =" https://logging.apache.org/xml/ns"
4+ xsi : schemaLocation =" https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+ type =" fixed" >
6+ <issue id =" 3257" link =" https://github.com/apache/logging-log4j2/issues/3257" />
7+ <description format =" asciidoc" >Fix detection of location requirements in `AsyncAppender`.</description >
8+ </entry >
You can’t perform that action at this time.
0 commit comments