Skip to content

Commit

Permalink
fix JaninoEvaluator issue/800, prepare release 1.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Apr 9, 2024
1 parent 370de39 commit 61140ea
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 17 deletions.
2 changes: 1 addition & 1 deletion logback-classic-blackbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-parent</artifactId>
<version>1.5.4-SNAPSHOT</version>
<version>1.5.4</version>
</parent>

<artifactId>logback-classic-blackbox</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
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;
import org.junit.jupiter.api.BeforeEach;
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion logback-classic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-parent</artifactId>
<version>1.5.4-SNAPSHOT</version>
<version>1.5.4</version>
</parent>

<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILoggingEvent> {

Expand All @@ -47,7 +48,8 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent
DEFAULT_PARAM_NAME_LIST.add("loggerContext");
DEFAULT_PARAM_NAME_LIST.add("level");
DEFAULT_PARAM_NAME_LIST.add("timeStamp");
// DEFAULT_PARAM_NAME_LIST.add("markerList");
DEFAULT_PARAM_NAME_LIST.add("marker");
DEFAULT_PARAM_NAME_LIST.add("markerList");
DEFAULT_PARAM_NAME_LIST.add("mdc");
DEFAULT_PARAM_NAME_LIST.add("throwableProxy");
DEFAULT_PARAM_NAME_LIST.add("throwable");
Expand All @@ -64,7 +66,8 @@ public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<ILoggingEvent
DEFAULT_PARAM_TYPE_LIST.add(LoggerContextVO.class);
DEFAULT_PARAM_TYPE_LIST.add(int.class);
DEFAULT_PARAM_TYPE_LIST.add(long.class);
// DEFAULT_PARAM_TYPE_LIST.add(List.class);
DEFAULT_PARAM_TYPE_LIST.add(Marker.class);
DEFAULT_PARAM_TYPE_LIST.add(MarkerList.class);
DEFAULT_PARAM_TYPE_LIST.add(Map.class);
DEFAULT_PARAM_TYPE_LIST.add(IThrowableProxy.class);
DEFAULT_PARAM_TYPE_LIST.add(Throwable.class);
Expand Down Expand Up @@ -123,7 +126,12 @@ protected Object[] getParameterValues(ILoggingEvent loggingEvent) {
// // In order to avoid NullPointerException, we could push a dummy marker if
// // the event's marker is null. However, this would surprise user who
// // expect to see a null marker instead of a dummy one.
// values[i++] = loggingEvent.getMarkerList();

MarkerList markerList = new MarkerList(loggingEvent.getMarkerList());
Marker marker = markerList.getFirstMarker();
values[i++] = marker;
values[i++] = markerList;

values[i++] = loggingEvent.getMDCPropertyMap();

IThrowableProxy iThrowableProxy = loggingEvent.getThrowableProxy();
Expand All @@ -146,5 +154,4 @@ protected Object[] getParameterValues(ILoggingEvent loggingEvent) {

return values;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2024, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/

package ch.qos.logback.classic.boolex;

import org.slf4j.Marker;

import java.util.List;

/**
* A helper class to be used in conjunction with {@link ch.qos.logback.classic.boolex.JaninoEventEvaluator}
*
* @since 1.5.4
*/
public class MarkerList {

List<Marker> markers;

public MarkerList(List<Marker> 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);
}
}
}
2 changes: 1 addition & 1 deletion logback-core-blackbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-parent</artifactId>
<version>1.5.4-SNAPSHOT</version>
<version>1.5.4</version>
</parent>

<artifactId>logback-core-blackbox</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion logback-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-parent</artifactId>
<version>1.5.4-SNAPSHOT</version>
<version>1.5.4</version>
</parent>

<artifactId>logback-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion logback-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-parent</artifactId>
<version>1.5.4-SNAPSHOT</version>
<version>1.5.4</version>
</parent>

<artifactId>logback-examples</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>ch.qos.logback</groupId>
<artifactId>logback-parent</artifactId>
<version>1.5.4-SNAPSHOT</version>
<version>1.5.4</version>
<packaging>pom</packaging>

<name>Logback-Parent</name>
Expand Down Expand Up @@ -48,7 +48,7 @@

<properties>
<!-- yyyy-MM-dd'T'HH:mm:ss'Z' -->
<project.build.outputTimestamp>2024-03-07T10:52:46Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-04-09T07:33:00Z</project.build.outputTimestamp>

<!-- minimal JDK version at runtime -->
<jdk.version>11</jdk.version>
Expand Down Expand Up @@ -93,7 +93,7 @@
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<license-maven-plugin.version>3.0</license-maven-plugin.version>
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
<maven-jxr-plugin.version>3.1.1</maven-jxr-plugin.version>
<maven-jxr-plugin.version>3.3.2</maven-jxr-plugin.version>
<maven-release-plugin.version>3.0.0-M4</maven-release-plugin.version>
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
<maven-dependency-plugin.version>3.2.0</maven-dependency-plugin.version>
Expand Down

0 comments on commit 61140ea

Please sign in to comment.