From 724f4fbcd6c3fbdef25ced240582cd840a20c288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20D=C3=A1niel?= Date: Wed, 26 Jun 2024 17:59:44 +0200 Subject: [PATCH 1/7] Added excludeLogEventIds options to client. The logger will exclude logs if the log event id is on the provided list. Prepare 9.3.0 release. --- gradle.properties | 2 +- .../java/com/configcat/ConfigCatClient.java | 10 +++++- .../java/com/configcat/ConfigCatLogger.java | 20 ++++++++---- src/main/java/com/configcat/Constants.java | 2 +- src/test/java/com/configcat/LoggerTests.java | 31 +++++++++++++++++++ 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8a06ad3..d2ead2d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=9.2.0 +version=9.3.0 diff --git a/src/main/java/com/configcat/ConfigCatClient.java b/src/main/java/com/configcat/ConfigCatClient.java index 261fcea..81b068e 100644 --- a/src/main/java/com/configcat/ConfigCatClient.java +++ b/src/main/java/com/configcat/ConfigCatClient.java @@ -28,7 +28,7 @@ public final class ConfigCatClient implements ConfigurationProvider { private final LogLevel clientLogLevel; private ConfigCatClient(String sdkKey, Options options) { - this.logger = new ConfigCatLogger(LoggerFactory.getLogger(ConfigCatClient.class), options.logLevel, options.configCatHooks); + this.logger = new ConfigCatLogger(LoggerFactory.getLogger(ConfigCatClient.class), options.logLevel, options.configCatHooks, options.excludeLogEventIds); this.clientLogLevel = options.logLevel; this.sdkKey = sdkKey; @@ -707,6 +707,7 @@ public static class Options { private User defaultUser; private boolean offline = false; private final ConfigCatHooks configCatHooks = new ConfigCatHooks(); + private List excludeLogEventIds; /** @@ -813,6 +814,13 @@ public ConfigCatHooks hooks() { return configCatHooks; } + /** + * Set the exclude Log Event Ids. + */ + public void excludeLogEventIds(List excludeLogEventIds) { + this.excludeLogEventIds = excludeLogEventIds; + } + private boolean isBaseURLCustom() { return this.baseUrl != null && !this.baseUrl.isEmpty(); } diff --git a/src/main/java/com/configcat/ConfigCatLogger.java b/src/main/java/com/configcat/ConfigCatLogger.java index 4b09b0e..c758bf3 100644 --- a/src/main/java/com/configcat/ConfigCatLogger.java +++ b/src/main/java/com/configcat/ConfigCatLogger.java @@ -2,19 +2,23 @@ import org.slf4j.Logger; +import java.util.List; + class ConfigCatLogger { private final Logger logger; private final LogLevel logLevel; private final ConfigCatHooks configCatHooks; + private final List excludeEventIds; - public ConfigCatLogger(Logger logger, LogLevel logLevel, ConfigCatHooks configCatHooks) { + public ConfigCatLogger(Logger logger, LogLevel logLevel, ConfigCatHooks configCatHooks, List excludeEventIds) { this.logger = logger; this.logLevel = logLevel; this.configCatHooks = configCatHooks; + this.excludeEventIds = excludeEventIds; } public ConfigCatLogger(Logger logger, LogLevel logLevel) { - this(logger, logLevel, null); + this(logger, logLevel, null, null); } public ConfigCatLogger(Logger logger) { @@ -22,27 +26,27 @@ public ConfigCatLogger(Logger logger) { } public void warn(int eventId, String message) { - if (this.logLevel.ordinal() <= LogLevel.WARNING.ordinal()) { + if (this.logLevel.ordinal() <= LogLevel.WARNING.ordinal() && !checkExcludeEventId(eventId)) { this.logger.warn("[{}] {}", eventId, message); } } public void error(int eventId, String message, Exception exception) { if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); - if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal()) { + if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkExcludeEventId(eventId)) { this.logger.error("[{}] {}", eventId, message, exception); } } public void error(int eventId, String message) { if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); - if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal()) { + if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkExcludeEventId(eventId)) { this.logger.error("[{}] {}", eventId, message); } } public void info(int eventId, String message) { - if (this.logLevel.ordinal() <= LogLevel.INFO.ordinal()) { + if (this.logLevel.ordinal() <= LogLevel.INFO.ordinal() && !checkExcludeEventId(eventId)) { this.logger.info("[{}] {}", eventId, message); } } @@ -52,4 +56,8 @@ public void debug(String message) { this.logger.debug("[{}] {}", 0, message); } } + + private boolean checkExcludeEventId(int eventId) { + return this.excludeEventIds != null && this.excludeEventIds.contains(eventId); + } } diff --git a/src/main/java/com/configcat/Constants.java b/src/main/java/com/configcat/Constants.java index 07d39ed..a51b5b3 100644 --- a/src/main/java/com/configcat/Constants.java +++ b/src/main/java/com/configcat/Constants.java @@ -7,7 +7,7 @@ private Constants() { /* prevent from instantiation*/ } static final long DISTANT_PAST = 0; static final String CONFIG_JSON_NAME = "config_v6.json"; static final String SERIALIZATION_FORMAT_VERSION = "v2"; - static final String VERSION = "9.2.0"; + static final String VERSION = "9.3.0"; static final String SDK_KEY_PROXY_PREFIX = "configcat-proxy/"; static final String SDK_KEY_PREFIX = "configcat-sdk-1"; diff --git a/src/test/java/com/configcat/LoggerTests.java b/src/test/java/com/configcat/LoggerTests.java index c7c5950..8cb8fd7 100644 --- a/src/test/java/com/configcat/LoggerTests.java +++ b/src/test/java/com/configcat/LoggerTests.java @@ -3,6 +3,9 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; +import java.util.ArrayList; +import java.util.List; + import static org.mockito.Mockito.*; public class LoggerTests { @@ -87,4 +90,32 @@ public void noLog() { verify(mockLogger, never()).warn(anyString(), eq(3000), eq("warn")); verify(mockLogger, never()).error(anyString(), eq(1000), eq("error"), any(Exception.class)); } + + @Test + public void excludeLogEvents() { + Logger mockLogger = mock(Logger.class); + + List excludeEventIds = new ArrayList<>(); + excludeEventIds.add(1001); + excludeEventIds.add(3001); + excludeEventIds.add(5001); + + ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.INFO, null, excludeEventIds); + + logger.debug("[0] debug"); + logger.info(5000, "info"); + logger.warn(3000, "warn"); + logger.error(1000, "error", new Exception()); + logger.info(5001, "info"); + logger.warn(3001, "warn"); + logger.error(1001, "error", new Exception()); + + verify(mockLogger, never()).debug(anyString(), eq(0), eq("debug")); + verify(mockLogger, times(1)).info(anyString(), eq(5000), eq("info")); + verify(mockLogger, times(1)).warn(anyString(), eq(3000), eq("warn")); + verify(mockLogger, times(1)).error(anyString(), eq(1000), eq("error"), any(Exception.class)); + verify(mockLogger, never()).info(anyString(), eq(5001), eq("info")); + verify(mockLogger, never()).warn(anyString(), eq(3001), eq("warn")); + verify(mockLogger, never()).error(anyString(), eq(1001), eq("error"), any(Exception.class)); + } } From bcc9f077671e71b5f8218efc523a9d5405e47a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20D=C3=A1niel?= Date: Thu, 27 Jun 2024 23:24:13 +0200 Subject: [PATCH 2/7] Replace eventId exclude list with filter function callback option. --- .../java/com/configcat/ConfigCatClient.java | 11 +++--- .../java/com/configcat/ConfigCatLogger.java | 22 +++++------ .../configcat/FilterFunctionParameters.java | 39 +++++++++++++++++++ src/test/java/com/configcat/LoggerTests.java | 10 ++--- 4 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/configcat/FilterFunctionParameters.java diff --git a/src/main/java/com/configcat/ConfigCatClient.java b/src/main/java/com/configcat/ConfigCatClient.java index 81b068e..4919c7a 100644 --- a/src/main/java/com/configcat/ConfigCatClient.java +++ b/src/main/java/com/configcat/ConfigCatClient.java @@ -8,6 +8,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; +import java.util.function.Function; /** * A client for handling configurations provided by ConfigCat. @@ -28,7 +29,7 @@ public final class ConfigCatClient implements ConfigurationProvider { private final LogLevel clientLogLevel; private ConfigCatClient(String sdkKey, Options options) { - this.logger = new ConfigCatLogger(LoggerFactory.getLogger(ConfigCatClient.class), options.logLevel, options.configCatHooks, options.excludeLogEventIds); + this.logger = new ConfigCatLogger(LoggerFactory.getLogger(ConfigCatClient.class), options.logLevel, options.configCatHooks, options.logFilterFunction); this.clientLogLevel = options.logLevel; this.sdkKey = sdkKey; @@ -707,7 +708,7 @@ public static class Options { private User defaultUser; private boolean offline = false; private final ConfigCatHooks configCatHooks = new ConfigCatHooks(); - private List excludeLogEventIds; + private Function logFilterFunction; /** @@ -815,10 +816,10 @@ public ConfigCatHooks hooks() { } /** - * Set the exclude Log Event Ids. + * Set the client's log filter callback function. When logFilterFunction returns true, the ConfigCatLogger skips the logging. */ - public void excludeLogEventIds(List excludeLogEventIds) { - this.excludeLogEventIds = excludeLogEventIds; + public void logFilterFunction(Function logFilterFunction) { + this.logFilterFunction = logFilterFunction; } private boolean isBaseURLCustom() { diff --git a/src/main/java/com/configcat/ConfigCatLogger.java b/src/main/java/com/configcat/ConfigCatLogger.java index c758bf3..5a81c18 100644 --- a/src/main/java/com/configcat/ConfigCatLogger.java +++ b/src/main/java/com/configcat/ConfigCatLogger.java @@ -2,19 +2,19 @@ import org.slf4j.Logger; -import java.util.List; +import java.util.function.Function; class ConfigCatLogger { private final Logger logger; private final LogLevel logLevel; private final ConfigCatHooks configCatHooks; - private final List excludeEventIds; + private final Function filterOutFunction; - public ConfigCatLogger(Logger logger, LogLevel logLevel, ConfigCatHooks configCatHooks, List excludeEventIds) { + public ConfigCatLogger(Logger logger, LogLevel logLevel, ConfigCatHooks configCatHooks, Function filterOutFunction) { this.logger = logger; this.logLevel = logLevel; this.configCatHooks = configCatHooks; - this.excludeEventIds = excludeEventIds; + this.filterOutFunction = filterOutFunction; } public ConfigCatLogger(Logger logger, LogLevel logLevel) { @@ -26,38 +26,38 @@ public ConfigCatLogger(Logger logger) { } public void warn(int eventId, String message) { - if (this.logLevel.ordinal() <= LogLevel.WARNING.ordinal() && !checkExcludeEventId(eventId)) { + if (this.logLevel.ordinal() <= LogLevel.WARNING.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.WARNING))) { this.logger.warn("[{}] {}", eventId, message); } } public void error(int eventId, String message, Exception exception) { if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); - if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkExcludeEventId(eventId)) { + if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.ERROR, exception))) { this.logger.error("[{}] {}", eventId, message, exception); } } public void error(int eventId, String message) { if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); - if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkExcludeEventId(eventId)) { + if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.ERROR))) { this.logger.error("[{}] {}", eventId, message); } } public void info(int eventId, String message) { - if (this.logLevel.ordinal() <= LogLevel.INFO.ordinal() && !checkExcludeEventId(eventId)) { + if (this.logLevel.ordinal() <= LogLevel.INFO.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.INFO))) { this.logger.info("[{}] {}", eventId, message); } } public void debug(String message) { - if (this.logLevel.ordinal() <= LogLevel.DEBUG.ordinal()) { + if (this.logLevel.ordinal() <= LogLevel.DEBUG.ordinal() && !checkFilterOut(new FilterFunctionParameters(0, message, LogLevel.DEBUG))) { this.logger.debug("[{}] {}", 0, message); } } - private boolean checkExcludeEventId(int eventId) { - return this.excludeEventIds != null && this.excludeEventIds.contains(eventId); + private boolean checkFilterOut(FilterFunctionParameters parameters) { + return this.filterOutFunction != null && this.filterOutFunction.apply(parameters); } } diff --git a/src/main/java/com/configcat/FilterFunctionParameters.java b/src/main/java/com/configcat/FilterFunctionParameters.java new file mode 100644 index 0000000..dbde464 --- /dev/null +++ b/src/main/java/com/configcat/FilterFunctionParameters.java @@ -0,0 +1,39 @@ +package com.configcat; + +public class FilterFunctionParameters { + + private final int eventId; + + private final String message; + + private final LogLevel logLevel; + + private final Exception exception; + + public FilterFunctionParameters(int eventId, String message, LogLevel logLevel, Exception exception) { + this.eventId = eventId; + this.message = message; + this.logLevel = logLevel; + this.exception = exception; + } + + public FilterFunctionParameters(int eventId, String message, LogLevel logLevel) { + this(eventId, message, logLevel, null); + } + + public int getEventId() { + return eventId; + } + + public Exception getException() { + return exception; + } + + public LogLevel getLogLevel() { + return logLevel; + } + + public String getMessage() { + return message; + } +} diff --git a/src/test/java/com/configcat/LoggerTests.java b/src/test/java/com/configcat/LoggerTests.java index 8cb8fd7..97a9082 100644 --- a/src/test/java/com/configcat/LoggerTests.java +++ b/src/test/java/com/configcat/LoggerTests.java @@ -3,8 +3,7 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.List; +import java.util.function.Function; import static org.mockito.Mockito.*; @@ -95,12 +94,9 @@ public void noLog() { public void excludeLogEvents() { Logger mockLogger = mock(Logger.class); - List excludeEventIds = new ArrayList<>(); - excludeEventIds.add(1001); - excludeEventIds.add(3001); - excludeEventIds.add(5001); + Function filterLogFunction = configCatLoggerFilterFunction -> configCatLoggerFilterFunction.getEventId() == 1001 || configCatLoggerFilterFunction.getEventId() == 3001 || configCatLoggerFilterFunction.getEventId() == 5001; - ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.INFO, null, excludeEventIds); + ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.INFO, null, filterLogFunction); logger.debug("[0] debug"); logger.info(5000, "info"); From a532607263316137c07d0db59e230a037ca26c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20D=C3=A1niel?= Date: Fri, 28 Jun 2024 14:27:18 +0200 Subject: [PATCH 3/7] Rework based on code review. --- .../java/com/configcat/ConfigCatClient.java | 8 ++-- .../java/com/configcat/ConfigCatLogger.java | 20 +++++----- .../configcat/FilterFunctionParameters.java | 39 ------------------- .../java/com/configcat/LogFilterFunction.java | 15 +++++++ src/test/java/com/configcat/LoggerTests.java | 2 +- 5 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/com/configcat/FilterFunctionParameters.java create mode 100644 src/main/java/com/configcat/LogFilterFunction.java diff --git a/src/main/java/com/configcat/ConfigCatClient.java b/src/main/java/com/configcat/ConfigCatClient.java index 4919c7a..3c58aeb 100644 --- a/src/main/java/com/configcat/ConfigCatClient.java +++ b/src/main/java/com/configcat/ConfigCatClient.java @@ -29,7 +29,7 @@ public final class ConfigCatClient implements ConfigurationProvider { private final LogLevel clientLogLevel; private ConfigCatClient(String sdkKey, Options options) { - this.logger = new ConfigCatLogger(LoggerFactory.getLogger(ConfigCatClient.class), options.logLevel, options.configCatHooks, options.logFilterFunction); + this.logger = new ConfigCatLogger(LoggerFactory.getLogger(ConfigCatClient.class), options.logLevel, options.configCatHooks, options.logFilter); this.clientLogLevel = options.logLevel; this.sdkKey = sdkKey; @@ -708,7 +708,7 @@ public static class Options { private User defaultUser; private boolean offline = false; private final ConfigCatHooks configCatHooks = new ConfigCatHooks(); - private Function logFilterFunction; + private LogFilterFunction logFilter; /** @@ -818,8 +818,8 @@ public ConfigCatHooks hooks() { /** * Set the client's log filter callback function. When logFilterFunction returns true, the ConfigCatLogger skips the logging. */ - public void logFilterFunction(Function logFilterFunction) { - this.logFilterFunction = logFilterFunction; + public void logFilter(LogFilterFunction logFilter) { + this.logFilter = logFilter; } private boolean isBaseURLCustom() { diff --git a/src/main/java/com/configcat/ConfigCatLogger.java b/src/main/java/com/configcat/ConfigCatLogger.java index 5a81c18..92fc4d0 100644 --- a/src/main/java/com/configcat/ConfigCatLogger.java +++ b/src/main/java/com/configcat/ConfigCatLogger.java @@ -8,13 +8,13 @@ class ConfigCatLogger { private final Logger logger; private final LogLevel logLevel; private final ConfigCatHooks configCatHooks; - private final Function filterOutFunction; + private final LogFilterFunction filterFunction ; - public ConfigCatLogger(Logger logger, LogLevel logLevel, ConfigCatHooks configCatHooks, Function filterOutFunction) { + public ConfigCatLogger(Logger logger, LogLevel logLevel, ConfigCatHooks configCatHooks, LogFilterFunction filterFunction ) { this.logger = logger; this.logLevel = logLevel; this.configCatHooks = configCatHooks; - this.filterOutFunction = filterOutFunction; + this.filterFunction = filterFunction ; } public ConfigCatLogger(Logger logger, LogLevel logLevel) { @@ -26,38 +26,38 @@ public ConfigCatLogger(Logger logger) { } public void warn(int eventId, String message) { - if (this.logLevel.ordinal() <= LogLevel.WARNING.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.WARNING))) { + if (filter(eventId, LogLevel.WARNING, message, null)) { this.logger.warn("[{}] {}", eventId, message); } } public void error(int eventId, String message, Exception exception) { if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); - if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.ERROR, exception))) { + if (filter(eventId, LogLevel.ERROR, message, exception)) { this.logger.error("[{}] {}", eventId, message, exception); } } public void error(int eventId, String message) { if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); - if (this.logLevel.ordinal() <= LogLevel.ERROR.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.ERROR))) { + if (filter(eventId, LogLevel.ERROR, message, null)) { this.logger.error("[{}] {}", eventId, message); } } public void info(int eventId, String message) { - if (this.logLevel.ordinal() <= LogLevel.INFO.ordinal() && !checkFilterOut(new FilterFunctionParameters(eventId, message, LogLevel.INFO))) { + if (filter(eventId, LogLevel.INFO, message, null)) { this.logger.info("[{}] {}", eventId, message); } } public void debug(String message) { - if (this.logLevel.ordinal() <= LogLevel.DEBUG.ordinal() && !checkFilterOut(new FilterFunctionParameters(0, message, LogLevel.DEBUG))) { + if (filter(0, LogLevel.DEBUG, message, null)) { this.logger.debug("[{}] {}", 0, message); } } - private boolean checkFilterOut(FilterFunctionParameters parameters) { - return this.filterOutFunction != null && this.filterOutFunction.apply(parameters); + private boolean filter(int eventId, LogLevel logLevel, String message, Exception exception) { + return this.logLevel.ordinal() <= logLevel.ordinal() && (this.filterFunction == null || this.filterFunction.apply(eventId, logLevel, message, exception)); } } diff --git a/src/main/java/com/configcat/FilterFunctionParameters.java b/src/main/java/com/configcat/FilterFunctionParameters.java deleted file mode 100644 index dbde464..0000000 --- a/src/main/java/com/configcat/FilterFunctionParameters.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.configcat; - -public class FilterFunctionParameters { - - private final int eventId; - - private final String message; - - private final LogLevel logLevel; - - private final Exception exception; - - public FilterFunctionParameters(int eventId, String message, LogLevel logLevel, Exception exception) { - this.eventId = eventId; - this.message = message; - this.logLevel = logLevel; - this.exception = exception; - } - - public FilterFunctionParameters(int eventId, String message, LogLevel logLevel) { - this(eventId, message, logLevel, null); - } - - public int getEventId() { - return eventId; - } - - public Exception getException() { - return exception; - } - - public LogLevel getLogLevel() { - return logLevel; - } - - public String getMessage() { - return message; - } -} diff --git a/src/main/java/com/configcat/LogFilterFunction.java b/src/main/java/com/configcat/LogFilterFunction.java new file mode 100644 index 0000000..7dec598 --- /dev/null +++ b/src/main/java/com/configcat/LogFilterFunction.java @@ -0,0 +1,15 @@ +package com.configcat; + +@FunctionalInterface +interface LogFilterFunction { + + /** + * + * @param eventId + * @param logLevel + * @param message + * @param exception + * @return + */ + boolean apply(int eventId, LogLevel logLevel , String message, Throwable exception); +} diff --git a/src/test/java/com/configcat/LoggerTests.java b/src/test/java/com/configcat/LoggerTests.java index 97a9082..a206aed 100644 --- a/src/test/java/com/configcat/LoggerTests.java +++ b/src/test/java/com/configcat/LoggerTests.java @@ -94,7 +94,7 @@ public void noLog() { public void excludeLogEvents() { Logger mockLogger = mock(Logger.class); - Function filterLogFunction = configCatLoggerFilterFunction -> configCatLoggerFilterFunction.getEventId() == 1001 || configCatLoggerFilterFunction.getEventId() == 3001 || configCatLoggerFilterFunction.getEventId() == 5001; + LogFilterFunction filterLogFunction = (int eventId, LogLevel logLevel , String message, Throwable exception) -> eventId != 1001 && eventId != 3001 && eventId != 5001; ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.INFO, null, filterLogFunction); From f89f80461651d602c0cf0645d5fa22b27bfec3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20D=C3=A1niel?= Date: Fri, 28 Jun 2024 14:36:41 +0200 Subject: [PATCH 4/7] Remove unused imports. --- src/main/java/com/configcat/ConfigCatClient.java | 1 - src/main/java/com/configcat/ConfigCatLogger.java | 2 -- src/test/java/com/configcat/LoggerTests.java | 2 -- 3 files changed, 5 deletions(-) diff --git a/src/main/java/com/configcat/ConfigCatClient.java b/src/main/java/com/configcat/ConfigCatClient.java index 3c58aeb..d7b8610 100644 --- a/src/main/java/com/configcat/ConfigCatClient.java +++ b/src/main/java/com/configcat/ConfigCatClient.java @@ -8,7 +8,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; -import java.util.function.Function; /** * A client for handling configurations provided by ConfigCat. diff --git a/src/main/java/com/configcat/ConfigCatLogger.java b/src/main/java/com/configcat/ConfigCatLogger.java index 92fc4d0..597d155 100644 --- a/src/main/java/com/configcat/ConfigCatLogger.java +++ b/src/main/java/com/configcat/ConfigCatLogger.java @@ -2,8 +2,6 @@ import org.slf4j.Logger; -import java.util.function.Function; - class ConfigCatLogger { private final Logger logger; private final LogLevel logLevel; diff --git a/src/test/java/com/configcat/LoggerTests.java b/src/test/java/com/configcat/LoggerTests.java index a206aed..68a6cef 100644 --- a/src/test/java/com/configcat/LoggerTests.java +++ b/src/test/java/com/configcat/LoggerTests.java @@ -3,8 +3,6 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; -import java.util.function.Function; - import static org.mockito.Mockito.*; public class LoggerTests { From aac1883ec8ff798dbca650b91aaa2c370e66323e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20D=C3=A1niel?= Date: Tue, 2 Jul 2024 15:49:24 +0200 Subject: [PATCH 5/7] Fix method order. Add missing JavaDoc. --- src/main/java/com/configcat/ConfigCatLogger.java | 2 +- .../java/com/configcat/LogFilterFunction.java | 16 ++++++++++------ src/test/java/com/configcat/LoggerTests.java | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/configcat/ConfigCatLogger.java b/src/main/java/com/configcat/ConfigCatLogger.java index 597d155..bd76edc 100644 --- a/src/main/java/com/configcat/ConfigCatLogger.java +++ b/src/main/java/com/configcat/ConfigCatLogger.java @@ -56,6 +56,6 @@ public void debug(String message) { } private boolean filter(int eventId, LogLevel logLevel, String message, Exception exception) { - return this.logLevel.ordinal() <= logLevel.ordinal() && (this.filterFunction == null || this.filterFunction.apply(eventId, logLevel, message, exception)); + return this.logLevel.ordinal() <= logLevel.ordinal() && (this.filterFunction == null || this.filterFunction.apply(logLevel, eventId, message, exception)); } } diff --git a/src/main/java/com/configcat/LogFilterFunction.java b/src/main/java/com/configcat/LogFilterFunction.java index 7dec598..91731e9 100644 --- a/src/main/java/com/configcat/LogFilterFunction.java +++ b/src/main/java/com/configcat/LogFilterFunction.java @@ -1,15 +1,19 @@ package com.configcat; +/** + * The Log Filter Functional Interface provides a custom filter option for the ConfigCat Logger. + */ @FunctionalInterface interface LogFilterFunction { /** + * Apply the custom filter option to the ConfigCatLogger. * - * @param eventId - * @param logLevel - * @param message - * @param exception - * @return + * @param logLevel Event severity level. + * @param eventId Event identifier. + * @param message Message. + * @param exception The exception object related to the message (if any). + * @return True to log the event, false will leave out the log. */ - boolean apply(int eventId, LogLevel logLevel , String message, Throwable exception); + boolean apply(LogLevel logLevel, int eventId, String message, Throwable exception); } diff --git a/src/test/java/com/configcat/LoggerTests.java b/src/test/java/com/configcat/LoggerTests.java index 68a6cef..0812ffd 100644 --- a/src/test/java/com/configcat/LoggerTests.java +++ b/src/test/java/com/configcat/LoggerTests.java @@ -92,7 +92,7 @@ public void noLog() { public void excludeLogEvents() { Logger mockLogger = mock(Logger.class); - LogFilterFunction filterLogFunction = (int eventId, LogLevel logLevel , String message, Throwable exception) -> eventId != 1001 && eventId != 3001 && eventId != 5001; + LogFilterFunction filterLogFunction = ( LogLevel logLevel, int eventId, String message, Throwable exception) -> eventId != 1001 && eventId != 3001 && eventId != 5001; ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.INFO, null, filterLogFunction); From 5490e69b9eaadfbef72fcdf6438fd7241f72b648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20D=C3=A1niel?= Date: Tue, 2 Jul 2024 17:29:24 +0200 Subject: [PATCH 6/7] Update src/main/java/com/configcat/ConfigCatClient.java Co-authored-by: adams85 <31276480+adams85@users.noreply.github.com> --- src/main/java/com/configcat/ConfigCatClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/configcat/ConfigCatClient.java b/src/main/java/com/configcat/ConfigCatClient.java index d7b8610..ac32a1e 100644 --- a/src/main/java/com/configcat/ConfigCatClient.java +++ b/src/main/java/com/configcat/ConfigCatClient.java @@ -815,7 +815,7 @@ public ConfigCatHooks hooks() { } /** - * Set the client's log filter callback function. When logFilterFunction returns true, the ConfigCatLogger skips the logging. + * Set the client's log filter callback function. When logFilterFunction returns false, the ConfigCatLogger skips the log event. */ public void logFilter(LogFilterFunction logFilter) { this.logFilter = logFilter; From 453eb97b347fa8e808f0103e06dd5ba3ae5d246e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20D=C3=A1niel?= Date: Tue, 2 Jul 2024 17:37:40 +0200 Subject: [PATCH 7/7] Fix interface visibility. --- src/main/java/com/configcat/LogFilterFunction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/configcat/LogFilterFunction.java b/src/main/java/com/configcat/LogFilterFunction.java index 91731e9..4c10e19 100644 --- a/src/main/java/com/configcat/LogFilterFunction.java +++ b/src/main/java/com/configcat/LogFilterFunction.java @@ -4,7 +4,7 @@ * The Log Filter Functional Interface provides a custom filter option for the ConfigCat Logger. */ @FunctionalInterface -interface LogFilterFunction { +public interface LogFilterFunction { /** * Apply the custom filter option to the ConfigCatLogger.