-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addded StubEventEvaluator as default class for evaluator element so a…
…s to direct users to the JaninoEventEvaluator migration tool Signed-off-by: Ceki Gulcu <ceki@qos.ch>
- Loading branch information
Showing
6 changed files
with
222 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...blackbox/src/test/java/ch/qos/logback/classic/blackbox/evaluator/MatchHelloEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2025, 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.blackbox.evaluator; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.boolex.EvaluationException; | ||
import ch.qos.logback.core.boolex.EventEvaluatorBase; | ||
|
||
public class MatchHelloEvaluator extends EventEvaluatorBase<ILoggingEvent> { | ||
|
||
String checkForInclusion; | ||
|
||
public void start() { | ||
if (checkForInclusion != null) { | ||
start(); | ||
} | ||
} | ||
|
||
public boolean evaluate(ILoggingEvent event) throws NullPointerException, EvaluationException { | ||
if (!isStarted()) { | ||
return false; | ||
} | ||
|
||
String message = event.getMessage(); | ||
boolean result = message.contains(checkForInclusion); | ||
return result; | ||
} | ||
|
||
public String getCheckForInclusion() { | ||
return checkForInclusion; | ||
} | ||
|
||
public void setCheckForInclusion(String checkForInclusion) { | ||
this.checkForInclusion = checkForInclusion; | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
logback-classic/src/main/java/ch/qos/logback/classic/boolex/StubEventEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2025, 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 ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.boolex.EvaluationException; | ||
import ch.qos.logback.core.boolex.EventEvaluatorBase; | ||
import ch.qos.logback.core.boolex.Matcher; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class StubEventEvaluator extends EventEvaluatorBase<ILoggingEvent> { | ||
|
||
static public final String MSG_0 = "This class is a stub for JaninoEventEvaluator which was removed in logback version 1.5.13"; | ||
static public final String MSG_1 = "You can migrate existing configurations to Java-only equivalents with the \"Janino Expression migrator\" tool at:"; | ||
static public final String MSG_2 ="https://logback.qos.ch/translator/services/janinoExpressionMigrator.html"; | ||
|
||
protected List<Matcher> matcherList = new ArrayList<>(); | ||
String expression; | ||
|
||
@Override | ||
public void start() { | ||
stop(); | ||
addWarn(MSG_0); | ||
addWarn(MSG_1); | ||
addWarn(MSG_2); | ||
} | ||
|
||
@Override | ||
public boolean evaluate(ILoggingEvent event) throws NullPointerException, EvaluationException { | ||
return false; | ||
} | ||
|
||
public String getExpression() { | ||
return expression; | ||
} | ||
|
||
public void setExpression(String expression) { | ||
this.expression = expression; | ||
} | ||
|
||
public void addMatcher(Matcher matcher) { | ||
matcherList.add(matcher); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
logback-classic/src/test/input/joran/basicEventEvaluator.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE configuration> | ||
|
||
<configuration> | ||
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/> | ||
<import class="ch.qos.logback.core.filter.EvaluatorFilter"/> | ||
<import class="ch.qos.logback.core.read.ListAppender"/> | ||
|
||
<appender name="LIST" class="ListAppender"> | ||
<filter class="EvaluatorFilter"> | ||
<evaluator> | ||
<expression>message.contains("billing")</expression> | ||
</evaluator> | ||
<onMismatch>NEUTRAL</onMismatch> | ||
<onMatch>DENY</onMatch> | ||
</filter> | ||
<encoder class="PatternLayoutEncoder"> | ||
<pattern>%-4relative [%thread] %-5level %logger - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="DEBUG"> | ||
<appender-ref ref="LIST"/> | ||
</root> | ||
</configuration> |
81 changes: 81 additions & 0 deletions
81
logback-classic/src/test/java/ch/qos/logback/classic/joran/sanity/EvaluatorStubTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2025, 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.joran.sanity; | ||
|
||
import ch.qos.logback.classic.ClassicTestConstants; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.boolex.StubEventEvaluator; | ||
import ch.qos.logback.classic.joran.JoranConfigurator; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.classic.util.LogbackMDCAdapter; | ||
import ch.qos.logback.core.joran.spi.JoranException; | ||
import ch.qos.logback.core.read.ListAppender; | ||
import ch.qos.logback.core.status.testUtil.StatusChecker; | ||
import ch.qos.logback.core.util.StatusPrinter2; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.slf4j.ILoggerFactory; | ||
import org.slf4j.spi.MDCAdapter; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class EvaluatorStubTest { | ||
LoggerContext loggerContext = new LoggerContext(); | ||
JoranConfigurator jc = new JoranConfigurator(); | ||
StatusPrinter2 statusPrinter2 = new StatusPrinter2(); | ||
StatusChecker statusChecker = new StatusChecker(loggerContext); | ||
MDCAdapter mdcAdapter = new LogbackMDCAdapter(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
loggerContext.setMDCAdapter(mdcAdapter); | ||
} | ||
|
||
@Test | ||
public void standaloneEventEvaluatorTest() throws JoranException { | ||
jc.setContext(loggerContext); | ||
jc.doConfigure(ClassicTestConstants.JORAN_INPUT_PREFIX + "simpleEvaluator.xml"); | ||
statusChecker.assertContainsMatch(StubEventEvaluator.MSG_0); | ||
statusChecker.assertContainsMatch(StubEventEvaluator.MSG_1); | ||
statusChecker.assertContainsMatch(StubEventEvaluator.MSG_2); | ||
//statusPrinter2.print(loggerContext); | ||
} | ||
|
||
@Test | ||
public void eventEvaluatorEmbeddedInFilterTest() throws JoranException { | ||
jc.setContext(loggerContext); | ||
jc.doConfigure(ClassicTestConstants.JORAN_INPUT_PREFIX + "basicEventEvaluator.xml"); | ||
statusChecker.assertContainsMatch(StubEventEvaluator.MSG_0); | ||
statusChecker.assertContainsMatch(StubEventEvaluator.MSG_1); | ||
statusChecker.assertContainsMatch(StubEventEvaluator.MSG_2); | ||
|
||
Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); | ||
|
||
ListAppender listAppender = (ListAppender) root.getAppender("LIST"); | ||
List<ILoggingEvent> eventList = listAppender.list; | ||
|
||
String message = "hello"; | ||
Logger logger = loggerContext.getLogger(this.getClass()); | ||
logger.warn(message); | ||
assertEquals(1, eventList.size()); | ||
assertEquals(message, eventList.get(0).getMessage()); | ||
statusPrinter2.print(loggerContext); | ||
} | ||
|
||
} |