From a61993d2c856b73f276a0ee92b4f3ff03ce22c43 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Mon, 18 Nov 2024 09:44:32 -0500 Subject: [PATCH 1/2] Ensure JUL OFF level is respected in liquibase logger Motivation ---------- An issue was found where the JUL OFF level was being logged at the error level. This is due to how the log level is determined using integer value checks. The ERROR level is the fallback when it should not be. Modifications ------------- A reproducer test was written for the issue and the ERROR threshold was checked to fix the issue. The OFF level is now the fallback which does nothing. Result ------ The result is the JUL OFF level is now respected. --- .../liquibase/logging/slf4j/Slf4jLogger.java | 7 ++++--- .../liquibase/logging/slf4j/Slf4jLoggerTest.java | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLogger.java b/src/main/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLogger.java index b9bd562..210a17f 100644 --- a/src/main/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLogger.java +++ b/src/main/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLogger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2023 Matt Bertolini + * Copyright (c) 2012-2024 Matt Bertolini * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the @@ -60,12 +60,13 @@ * @author Matt Bertolini * @see liquibase.logging.Logger */ -public class Slf4jLogger extends AbstractLogger { +public class Slf4jLogger extends AbstractLogger implements liquibase.logging.Logger { private static final int TRACE_THRESHOLD = Level.FINEST.intValue(); private static final int DEBUG_THRESHOLD = Level.FINE.intValue(); private static final int INFO_THRESHOLD = Level.INFO.intValue(); private static final int WARN_THRESHOLD = Level.WARNING.intValue(); + private static final int ERROR_THRESHOLD = Level.SEVERE.intValue(); private final Logger logger; @@ -85,7 +86,7 @@ public void log(Level level, String message, Throwable e) { logger.info(message, e); } else if (levelValue <= WARN_THRESHOLD) { logger.warn(message, e); - } else { + } else if (levelValue <= ERROR_THRESHOLD) { logger.error(message, e); } } diff --git a/src/test/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLoggerTest.java b/src/test/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLoggerTest.java index 0680451..ceb1dfe 100644 --- a/src/test/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLoggerTest.java +++ b/src/test/java/com/mattbertolini/liquibase/logging/slf4j/Slf4jLoggerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2023 Matt Bertolini + * Copyright (c) 2012-2024 Matt Bertolini * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the @@ -28,6 +28,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; /** @@ -88,6 +89,12 @@ void logWithFinestLevel() { verify(delegate).trace(message, (Throwable) null); } + @Test + void doesNotLogWithOffLevel() { + logger.log(Level.OFF, "should not log", null); + verifyNoInteractions(delegate); + } + // Severe level @Test From 2e795b126a58e408527bf74f9b3a6ae3be844d11 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Mon, 18 Nov 2024 20:20:21 -0500 Subject: [PATCH 2/2] Update workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61e2246..7a0414b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: - '*' pull_request: branches: - - $default-branch + - '*' jobs: build: