Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wsargent committed Dec 20, 2024
1 parent 779fb1a commit d491c4f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
17 changes: 11 additions & 6 deletions jsonpath/src/main/java/echopraxia/jsonpath/JsonPathCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
import echopraxia.logging.api.Level;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class JsonPathCondition {

public static Condition pathCondition(Function<LoggingContextWithFindPathMethods, Boolean> o) {
@Contract(pure = true)
public static @NotNull Condition pathCondition(
Function<LoggingContextWithFindPathMethods, Boolean> o) {
return (level, context) -> {
if (context instanceof LoggingContextWithFindPathMethods) {
return o.apply((LoggingContextWithFindPathMethods) context);
} else {
// XXX should log something here.
return false;
throw new IllegalStateException(
"pathCondition requires LoggingContextWithFindPathMethods instance!");
}
};
}

public static Condition pathCondition(
@Contract(pure = true)
public static @NotNull Condition pathCondition(
BiFunction<Level, LoggingContextWithFindPathMethods, Boolean> o) {
return (level, context) -> {
if (context instanceof LoggingContextWithFindPathMethods) {
return o.apply(level, (LoggingContextWithFindPathMethods) context);
} else {
// XXX should log something here.
return false;
throw new IllegalStateException(
"pathCondition requires LoggingContextWithFindPathMethods instance!");
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions logback/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ dependencies {
compileOnly "ch.qos.logback:logback-classic:$logbackVersion"

testImplementation(testFixtures(project(':logging')))
testImplementation "org.slf4j:slf4j-api:1.7.36"
testImplementation "ch.qos.logback:logback-classic:1.2.12"
testImplementation "org.slf4j:slf4j-api:$slf4jApiVersion"
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ public FilterReply decide(
return FilterReply.NEUTRAL;
}

@NotNull
private Level level(ch.qos.logback.classic.Level level) {
return Level.valueOf(level.levelStr);
}

private LoggingContext loggingContext(Marker marker, Object[] arguments) {
@NotNull
private LogbackLoggingContext loggingContext(Marker marker, Object[] arguments) {
FilterMarkerContext markerContext = new FilterMarkerContext(marker);
return new LogbackLoggingContext(null, markerContext, () -> getFields(arguments));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import echopraxia.api.Field;
import echopraxia.jsonpath.AbstractJsonPathFinder;
import echopraxia.logging.api.LoggingContext;
import echopraxia.jsonpath.LoggingContextWithFindPathMethods;
import echopraxia.logging.spi.CoreLogger;
import java.util.Collections;
import java.util.List;
Expand All @@ -17,7 +17,8 @@
* The logging context composes the "logger context" (markers/fields associated with the logger) and
* the field arguments associated with the individual logging event.
*/
public class LogbackLoggingContext extends AbstractJsonPathFinder implements LoggingContext {
public class LogbackLoggingContext extends AbstractJsonPathFinder
implements LoggingContextWithFindPathMethods {

private final Supplier<List<Field>> argumentFields;
private final Supplier<List<Field>> loggerFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ public static Condition create(

@Override
public boolean test(Level level, LoggingContext context) {
// XXX should be a better test here
return scriptManager.execute(defaultValue, level, (LoggingContextWithFindPathMethods) context);
if (context instanceof LoggingContextWithFindPathMethods) {
return scriptManager.execute(
defaultValue, level, (LoggingContextWithFindPathMethods) context);
} else {
throw new IllegalStateException(
"ScriptCondition requires a LoggingContextWithFindPathMethods instance!");
}
}
}

0 comments on commit d491c4f

Please sign in to comment.