Repository navigation
Conversation
… path degradation PR 5 of 6 in the diagnostic logging series (b/584840083, part 2 of 2). Isolates per-connection LogLevel and LogPath slots inside a single persistent PerConnectionFileHandler without stripping OpenTelemetryJulHandler or external JUL handlers on LogLevel=0, degrades gracefully on unwritable/invalid/symlinked LogPath without failing Driver.connect, and computes the root logger threshold dynamically across open connections.
There was a problem hiding this comment.
Code Review
This pull request updates the BigQuery JDBC driver's logging mechanism to support per-connection logging levels and paths, introducing PerConnectionFileHandler and updating BigQueryJdbcRootLogger to dynamically manage active connections and handle external handlers. The review feedback suggests two key improvements: passing the exception object directly to logger.log instead of using string concatenation to preserve the stack trace, and explicitly resetting several static fields in resetForTesting() to prevent state leakage and ensure test isolation.
| } catch (Exception ex) { | ||
| logger.warning("Log File warning : " + ex); | ||
| } |
There was a problem hiding this comment.
When catching an exception and logging it, avoid using string concatenation with the exception object (e.g., + ex) as it discards the stack trace and makes debugging difficult. Instead, pass the exception object as the third argument to logger.log to preserve the full stack trace.
| } catch (Exception ex) { | |
| logger.warning("Log File warning : " + ex); | |
| } | |
| } catch (Exception ex) { | |
| logger.log(Level.WARNING, "Log File warning", ex); | |
| } |
| static synchronized void resetForTesting() { | ||
| for (String id : ACTIVE_CONNECTIONS.keySet()) { | ||
| ConnectionLogContext ctx = ACTIVE_CONNECTIONS.remove(id); | ||
| if (ctx != null) { | ||
| ctx.setLevelValue(ConnectionLogContext.OFF_VALUE); | ||
| } | ||
| if (persistentFileHandler != null) { | ||
| persistentFileHandler.closeHandler(id); | ||
| } | ||
| } | ||
| if (fileHandler != null) { | ||
| fileHandler.close(); | ||
| logger.removeHandler(fileHandler); | ||
| fileHandler = null; | ||
| } | ||
| explicitGlobalLevel = Level.OFF; | ||
| refreshEffectiveRootLevel(); | ||
| } |
There was a problem hiding this comment.
To prevent state leakage and ensure test isolation, explicitly reset the static fields lastDriverAppliedLevel, hasExternalFloor, and externalFloorLevel to their default values in resetForTesting() before calling refreshEffectiveRootLevel().
static synchronized void resetForTesting() {
for (String id : ACTIVE_CONNECTIONS.keySet()) {
ConnectionLogContext ctx = ACTIVE_CONNECTIONS.remove(id);
if (ctx != null) {
ctx.setLevelValue(ConnectionLogContext.OFF_VALUE);
}
if (persistentFileHandler != null) {
persistentFileHandler.closeHandler(id);
}
}
if (fileHandler != null) {
fileHandler.close();
logger.removeHandler(fileHandler);
fileHandler = null;
}
explicitGlobalLevel = Level.OFF;
lastDriverAppliedLevel = null;
hasExternalFloor = false;
externalFloorLevel = null;
refreshEffectiveRootLevel();
}63f8a7c to
3b01d92
Compare
3b01d92 to
a209aeb
Compare
Summary
PR 5 of 6 in the diagnostic logging stack (
b/584840083, part 2 of 2; stacked onfix/bq-jdbc-url-log-masking). Replaces global handler replacement onBigQueryJdbcRootLoggerwith a persistent multi-connectionPerConnectionFileHandlerso concurrent connections maintain isolated(LogLevel, LogPath)slots and preserve shared JUL/OpenTelemetry handlers.Environment Variables & System Properties
BIGQUERY_JDBC_LOG_LEVELandBIGQUERY_JDBC_LOG_PATHhandling soBQ-JDBC-GLOBAL.logis opened only when both JVM-level environment variables are configured).Design Decisions
PerConnectionFileHandlerwith per-connection(LogPath, LogLevel)slots: Previously, opening a new connection replaced and closed the singleFileHandleroncom.google.cloud.bigquery, redirecting or silencing concurrent connections. Storing per-connectionIdslots inside one persistent handler isolates file destinations and thresholds across concurrent connections.com.google.cloud.bigqueryroot level as the minimum (most verbose) active level across open connections, preservesOpenTelemetryJulHandler,ConsoleHandler, and externally attached JUL handlers when a connection specifiesLogLevel=0, and restores any external handler floor when verbose connections close.LogPathdegradation: If a connection'sLogPathis unwritable, read-only, non-directory, symlinked, or syntactically invalid,registerConnection/publishIfOpencloses that connection's file slot and reports once via JULErrorManagerwithout throwing fromDriverManager.getConnection(...)or retrying failed file opens on every subsequent log record.