From 61140ea1005688ae94500d93d191909fd7ef3cfb Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Tue, 9 Apr 2024 09:35:05 +0200 Subject: [PATCH] fix JaninoEvaluator issue/800, prepare release 1.5.4 --- logback-classic-blackbox/pom.xml | 2 +- .../BlackboxJaninoEventEvaluatorTest.java | 24 +++++-- logback-classic/pom.xml | 2 +- .../classic/boolex/JaninoEventEvaluator.java | 15 +++-- .../logback/classic/boolex/MarkerList.java | 64 +++++++++++++++++++ logback-core-blackbox/pom.xml | 2 +- logback-core/pom.xml | 2 +- logback-examples/pom.xml | 2 +- pom.xml | 6 +- 9 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 logback-classic/src/main/java/ch/qos/logback/classic/boolex/MarkerList.java diff --git a/logback-classic-blackbox/pom.xml b/logback-classic-blackbox/pom.xml index 4945fec4c2..41f77a6ada 100644 --- a/logback-classic-blackbox/pom.xml +++ b/logback-classic-blackbox/pom.xml @@ -8,7 +8,7 @@ ch.qos.logback logback-parent - 1.5.4-SNAPSHOT + 1.5.4 logback-classic-blackbox diff --git a/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/boolex/BlackboxJaninoEventEvaluatorTest.java b/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/boolex/BlackboxJaninoEventEvaluatorTest.java index bf31305a31..8e32fcb42a 100644 --- a/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/boolex/BlackboxJaninoEventEvaluatorTest.java +++ b/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/boolex/BlackboxJaninoEventEvaluatorTest.java @@ -14,6 +14,7 @@ package ch.qos.logback.classic.blackbox.boolex; import java.io.IOException; +import java.util.List; import ch.qos.logback.classic.boolex.JaninoEventEvaluator; import ch.qos.logback.classic.util.LogbackMDCAdapter; @@ -21,6 +22,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.MDC; +import org.slf4j.Marker; import org.slf4j.MarkerFactory; import ch.qos.logback.classic.Level; @@ -121,10 +123,22 @@ public void mdcAsString() throws Exception { logbackMDCAdapter.remove(k); } - @Disabled + @Test + public void markerList() throws Exception { + + jee.setExpression("markerList.contains(\"BLUE\")"); + jee.start(); + + LoggingEvent event = makeLoggingEvent(null); + event.addMarker(MarkerFactory.getMarker("BLUE")); + StatusPrinter.print(loggerContext); + assertTrue(jee.evaluate(event)); + } + @Test public void marker() throws Exception { - jee.setExpression("markerList.stream().anyMatch( m -> m.contains(\"BLUE\"))"); + + jee.setExpression("marker.contains(\"BLUE\")"); jee.start(); LoggingEvent event = makeLoggingEvent(null); @@ -133,10 +147,10 @@ public void marker() throws Exception { assertTrue(jee.evaluate(event)); } - @Disabled + // LBCORE_118 @Test - public void withNullMarker_LBCORE_118() throws Exception { - jee.setExpression("markerList.contains(\"BLUE\")"); + public void withNullMarker_LOGBACK_63() throws Exception { + jee.setExpression("marker.contains(\"BLUE\")"); jee.start(); ILoggingEvent event = makeLoggingEvent(null); diff --git a/logback-classic/pom.xml b/logback-classic/pom.xml index 93ba3bca8a..6866d4289f 100755 --- a/logback-classic/pom.xml +++ b/logback-classic/pom.xml @@ -8,7 +8,7 @@ ch.qos.logback logback-parent - 1.5.4-SNAPSHOT + 1.5.4 logback-classic diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java b/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java index 77cfa3acb1..d5055c2ebe 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java @@ -25,6 +25,7 @@ import ch.qos.logback.core.CoreConstants; import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase; import ch.qos.logback.core.boolex.Matcher; +import org.slf4j.Marker; public class JaninoEventEvaluator extends JaninoEventEvaluatorBase { @@ -47,7 +48,8 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase markers; + + public MarkerList(List markers) { + this.markers = markers; + } + + /** + * Check whether this list contains a given marker. + * + * @param markerName + * @return + */ + public boolean contains(String markerName) { + if(markerName == null || markerName.trim().length() == 0) + return false; + + if(markers == null || markers.isEmpty()) + return false; + + final boolean result = markers.stream().anyMatch( m -> m.contains(markerName)); + return result; + } + + /** + * Return the first marker on the list, can be null. + * + * + * @return the first marker on the list, can be null + */ + public Marker getFirstMarker() { + if(markers == null || markers.isEmpty()) { + return null; + } else { + return markers.get(0); + } + } +} diff --git a/logback-core-blackbox/pom.xml b/logback-core-blackbox/pom.xml index e65c29735b..75eb0a7896 100644 --- a/logback-core-blackbox/pom.xml +++ b/logback-core-blackbox/pom.xml @@ -8,7 +8,7 @@ ch.qos.logback logback-parent - 1.5.4-SNAPSHOT + 1.5.4 logback-core-blackbox diff --git a/logback-core/pom.xml b/logback-core/pom.xml index 22eb539f74..8816596141 100755 --- a/logback-core/pom.xml +++ b/logback-core/pom.xml @@ -8,7 +8,7 @@ ch.qos.logback logback-parent - 1.5.4-SNAPSHOT + 1.5.4 logback-core diff --git a/logback-examples/pom.xml b/logback-examples/pom.xml index 8bdac8edf1..ab6a8b1388 100755 --- a/logback-examples/pom.xml +++ b/logback-examples/pom.xml @@ -8,7 +8,7 @@ ch.qos.logback logback-parent - 1.5.4-SNAPSHOT + 1.5.4 logback-examples diff --git a/pom.xml b/pom.xml index 3d384bb2f2..fd2451bae4 100755 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ ch.qos.logback logback-parent - 1.5.4-SNAPSHOT + 1.5.4 pom Logback-Parent @@ -48,7 +48,7 @@ - 2024-03-07T10:52:46Z + 2024-04-09T07:33:00Z 11 @@ -93,7 +93,7 @@ 3.1.0 3.0 3.2.2 - 3.1.1 + 3.3.2 3.0.0-M4 3.0.0-M1 3.2.0