20
20
import java .util .Arrays ;
21
21
import java .util .List ;
22
22
import java .util .Map ;
23
+ import java .util .function .Predicate ;
23
24
import org .apache .logging .log4j .Level ;
24
25
import org .apache .logging .log4j .LogManager ;
25
26
import org .apache .logging .log4j .Marker ;
26
27
import org .apache .logging .log4j .core .Appender ;
27
28
import org .apache .logging .log4j .core .Filter ;
28
29
import org .apache .logging .log4j .core .LogEvent ;
29
30
import org .apache .logging .log4j .core .LoggerContext ;
30
- import org .apache .logging .log4j .core .async .AsyncLoggerConfig ;
31
- import org .apache .logging .log4j .core .async .AsyncLoggerContext ;
32
- import org .apache .logging .log4j .core .async .AsyncLoggerContextSelector ;
33
31
import org .apache .logging .log4j .core .config .plugins .PluginConfiguration ;
34
32
import org .apache .logging .log4j .core .filter .AbstractFilterable ;
35
33
import org .apache .logging .log4j .core .impl .Log4jLogEvent ;
@@ -495,7 +493,7 @@ public void log(
495
493
final LogEvent logEvent =
496
494
logEventFactory .createEvent (loggerName , marker , fqcn , location (fqcn ), level , data , props , t );
497
495
try {
498
- log (logEvent , LoggerConfigPredicate . ALL );
496
+ log (logEvent , null );
499
497
} finally {
500
498
// LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString())
501
499
logEventFactory .recycle (logEvent );
@@ -530,7 +528,7 @@ public void log(
530
528
final LogEvent logEvent =
531
529
logEventFactory .createEvent (loggerName , marker , fqcn , location , level , data , props , t );
532
530
try {
533
- log (logEvent , LoggerConfigPredicate . ALL );
531
+ log (logEvent , null );
534
532
} finally {
535
533
// LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString())
536
534
logEventFactory .recycle (logEvent );
@@ -584,17 +582,17 @@ private List<Property> getPropertiesWithLookups(
584
582
* @param event The log event.
585
583
*/
586
584
public void log (final LogEvent event ) {
587
- log (event , LoggerConfigPredicate . ALL );
585
+ log (event , null );
588
586
}
589
587
590
588
/**
591
589
* Logs an event.
592
590
*
593
591
* @param event The log event.
594
- * @param predicate predicate for which LoggerConfig instances to append to. A
595
- * {@literal null} value is equivalent to a true predicate.
592
+ * @param predicate predicate for which LoggerConfig instances to append to.
593
+ * Use a {@literal null} value instead of a true predicate.
596
594
*/
597
- protected void log (final LogEvent event , final LoggerConfigPredicate predicate ) {
595
+ protected void log (final LogEvent event , final Predicate < LoggerConfig > predicate ) {
598
596
if (!isFiltered (event )) {
599
597
processLogEvent (event , predicate );
600
598
}
@@ -614,12 +612,12 @@ public ReliabilityStrategy getReliabilityStrategy() {
614
612
* Logs an event, bypassing filters.
615
613
*
616
614
* @param event The log event.
617
- * @param predicate predicate for which LoggerConfig instances to append to. A
618
- * {@literal null} value is equivalent to a true predicate.
615
+ * @param predicate predicate for which LoggerConfig instances to append to.
616
+ * Use a {@literal null} value instead of a true predicate.
619
617
*/
620
- protected void processLogEvent (final LogEvent event , final LoggerConfigPredicate predicate ) {
618
+ protected void processLogEvent (final LogEvent event , final Predicate < LoggerConfig > predicate ) {
621
619
event .setIncludeLocation (isIncludeLocation ());
622
- if (predicate == null || predicate .allow (this )) {
620
+ if (predicate == null || predicate .test (this )) {
623
621
callAppenders (event );
624
622
}
625
623
logParent (event , predicate );
@@ -649,7 +647,7 @@ public boolean requiresLocation() {
649
647
return false ;
650
648
}
651
649
652
- private void logParent (final LogEvent event , final LoggerConfigPredicate predicate ) {
650
+ private void logParent (final LogEvent event , final Predicate < LoggerConfig > predicate ) {
653
651
if (additive && parent != null ) {
654
652
parent .log (event , predicate );
655
653
}
@@ -674,14 +672,11 @@ public String toString() {
674
672
protected static boolean includeLocation (
675
673
final String includeLocationConfigValue , final Configuration configuration ) {
676
674
if (includeLocationConfigValue == null ) {
677
- LoggerContext context = null ;
678
675
if (configuration != null ) {
679
- context = configuration .getLoggerContext ();
680
- }
681
- if (context != null ) {
682
- return !(context instanceof AsyncLoggerContext );
676
+ final LoggerContext context = configuration .getLoggerContext ();
677
+ return context != null ? context .includeLocation () : false ;
683
678
} else {
684
- return ! AsyncLoggerContextSelector . isSelected () ;
679
+ return false ;
685
680
}
686
681
}
687
682
return Boolean .parseBoolean (includeLocationConfigValue );
@@ -860,27 +855,4 @@ protected static class LevelAndRefs {
860
855
public Level level ;
861
856
public List <AppenderRef > refs ;
862
857
}
863
-
864
- protected enum LoggerConfigPredicate {
865
- ALL () {
866
- @ Override
867
- boolean allow (final LoggerConfig config ) {
868
- return true ;
869
- }
870
- },
871
- ASYNCHRONOUS_ONLY () {
872
- @ Override
873
- boolean allow (final LoggerConfig config ) {
874
- return config instanceof AsyncLoggerConfig ;
875
- }
876
- },
877
- SYNCHRONOUS_ONLY () {
878
- @ Override
879
- boolean allow (final LoggerConfig config ) {
880
- return !ASYNCHRONOUS_ONLY .allow (config );
881
- }
882
- };
883
-
884
- abstract boolean allow (LoggerConfig config );
885
- }
886
858
}
0 commit comments