Skip to content

Commit

Permalink
Change logic to avoid calling setParent (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbagnard authored Jul 30, 2024
1 parent b7994a6 commit 401a6ed
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/com/mongodb/jdbc/logging/MongoLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.mongodb.jdbc.logging;

import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -73,11 +74,19 @@ private void createLogger(String className, MongoLogger parentLogger) {
? className
: parentLogger.connectionId + "_" + className;
this.logger = Logger.getLogger(loggername);
logger.setParent(parentLogger.logger);
logger.setLevel(parentLogger.logger.getLevel());
// Make sure to allow using parent handler
logger.setUseParentHandlers(true);

// This is a work-around for the simpler logic of calling `logger.setParent(parent); logger.setUseParentHandlers(true);`
// after configuring the parent logger handlers for the connection.
// This is to avoid issue with log managers which are restricting use of setParent like JBoss Log Manager for example.
for (Handler handler : logger.getHandlers()) {
// Clean the handler list to avoid any duplication of logs from transitive handlers
logger.removeHandler(handler);
}
for (Handler handler : parentLogger.logger.getHandlers()) {
// Add all parent handlers
logger.addHandler(handler);
}
this.connectionId = parentLogger.connectionId;
}

Expand Down

0 comments on commit 401a6ed

Please sign in to comment.