Skip to content

Commit 6e84664

Browse files
Fix logging not being suppressed when LogLevel.OFF is configured (#1167)
## Description NO_CHANGELOG=true <!-- Provide a brief summary of the changes made and the issue they aim to address.--> When LogLevel.OFF was set, setupLogger() returned early without configuring the JUL logger. This caused Java's default logging behavior to kick in, resulting in deprecation warnings (e.g., ignoreTransactions warnings) being logged to console despite logging being disabled. Now properly initializes the logger with Level.OFF to suppress all output while using STDOUT to avoid file system access issues in restricted environments. Fixes #1158 ## Testing <!-- Describe how the changes have been tested--> Manual testing ## Additional Notes to the Reviewer <!-- Share any additional context or insights that may help the reviewer understand the changes better. This could include challenges faced, limitations, or compromises made during the development process. Also, mention any areas of the code that you would like the reviewer to focus on specifically. -->
1 parent 56f872b commit 6e84664

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/main/java/com/databricks/jdbc/common/util/LoggingUtil.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ public class LoggingUtil {
1717

1818
public static void setupLogger(String logDir, int logFileSizeMB, int logFileCount, LogLevel level)
1919
throws IOException {
20-
if (level == LogLevel.OFF) {
21-
// Skip handler initialization to avoid AccessDeniedException in restricted environments
22-
return;
23-
}
2420
if (LOGGER instanceof JulLogger && System.getProperty(JAVA_UTIL_LOGGING_CONFIG_FILE) == null) {
2521
// Only configure JUL logger if it's not already configured via external properties file
22+
if (level == LogLevel.OFF) {
23+
// Initialize logger with OFF level to properly suppress all output.
24+
// Without this, JUL falls back to default behavior and logs warnings to console.
25+
JulLogger.initLogger(Level.OFF, JulLogger.STDOUT, 0, 0);
26+
return;
27+
}
2628
JulLogger.initLogger(toJulLevel(level), logDir, logFileSizeMB * 1024 * 1024, logFileCount);
2729
LOGGER.info("Setting up JUL logger");
2830
}

src/test/java/com/databricks/jdbc/common/util/LoggingUtilTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ void testSetupLogger() {
2020

2121
@Test
2222
void testSetupLoggerWithOffLevel() {
23-
// When log level is OFF, setupLogger should return early without initializing handlers
24-
// This should not throw an exception even if the log path is not writable
23+
// When log level is OFF, setupLogger initializes logger with Level.OFF to suppress all output.
24+
// It uses STDOUT to avoid file system access issues in restricted environments.
25+
// This should not throw an exception even if the log path is not writable.
2526
assertDoesNotThrow(() -> LoggingUtil.setupLogger("/", 1, 1, LogLevel.OFF));
2627
assertDoesNotThrow(() -> LoggingUtil.setupLogger("/invalid/path", 1, 1, LogLevel.OFF));
2728
}

0 commit comments

Comments
 (0)