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 bd38f79138 Defer fetching of the filter configuration until the first 
poll to prevent application startup from being blocked
bd38f79138 is described below

commit bd38f791387cd40b454ddefba5f9dbd93e7895fd
Author: Ralph Goers <[email protected]>
AuthorDate: Wed May 11 14:00:43 2022 -0700

    Defer fetching of the filter configuration until the first poll to prevent 
application startup from being blocked
---
 .../core/filter/MutableThreadContextMapFilter.java | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MutableThreadContextMapFilter.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MutableThreadContextMapFilter.java
index 7eb949a192..3bbc51be21 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MutableThreadContextMapFilter.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/MutableThreadContextMapFilter.java
@@ -244,29 +244,28 @@ public class MutableThreadContextMapFilter extends 
AbstractFilter {
         public MutableThreadContextMapFilter build() {
             final LastModifiedSource source = getSource(configLocation);
             if (source == null) {
-               return new MutableThreadContextMapFilter(new NoOpFilter(), 
null, 0,
-                       null, getOnMatch(), getOnMismatch(), configuration);
+                return new MutableThreadContextMapFilter(new NoOpFilter(), 
null, 0,
+                        null, getOnMatch(), getOnMismatch(), configuration);
             }
             final AuthorizationProvider authorizationProvider =
                     
ConfigurationFactory.authorizationProvider(PropertiesUtil.getProperties());
-            final ConfigResult result = getConfig(source, 
authorizationProvider);
             Filter filter;
-            if (result.status == Status.SUCCESS) {
-                if (result.pairs.length > 0) {
-                    filter = ThreadContextMapFilter.newBuilder()
-                            .setPairs(result.pairs)
-                            .setOperator("or")
-                            .setOnMatch(getOnMatch())
-                            .setOnMismatch(getOnMismatch())
-                            
.setContextDataInjector(ContextDataInjectorFactory.createInjector())
-                            .get();
+            if (pollInterval <= 0) {
+                ConfigResult result = getConfig(source, authorizationProvider);
+                if (result.status == Status.SUCCESS) {
+                    if (result.pairs.length > 0) {
+                        filter = 
ThreadContextMapFilter.createFilter(result.pairs, "or",
+                                getOnMatch(), getOnMismatch());
+                    } else {
+                        filter = new NoOpFilter();
+                    }
+                } else if (result.status == Status.NOT_FOUND || result.status 
== Status.EMPTY) {
+                    filter = new NoOpFilter();
                 } else {
+                    LOGGER.warn("Unexpected response returned on initial call: 
{}", result.status);
                     filter = new NoOpFilter();
                 }
-            } else if (result.status == Status.NOT_FOUND || result.status == 
Status.EMPTY) {
-                filter = new NoOpFilter();
             } else {
-                LOGGER.warn("Unexpected response returned on initial call: 
{}", result.status);
                 filter = new NoOpFilter();
             }
 

Reply via email to