diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java index 0505a2204a..5a6e6d7bfa 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java @@ -23,6 +23,7 @@ import org.jlab.utils.groups.IndexedTableViewer; import org.jlab.utils.system.FileSystemExecScan; import org.jlab.logging.SplitLogManager; +import org.jlab.logging.LogLevelGuard; /** * @@ -34,6 +35,7 @@ public class DatabaseConstantProvider implements ConstantProvider { static { SplitLogManager.configureHandlers(LOGGER, false); } + private LogLevelGuard logGuard = new LogLevelGuard("org.freehep.math.minuit"); private final HashMap constantContainer = new HashMap<>(); private final boolean PRINT_ALL = true; @@ -148,7 +150,9 @@ private void initialize(String address){ LOGGER.log(Level.INFO, String.format("[DB] ---> open %s | %s | %s | %s", runNumber, variation, databaseDate, address)); + logGuard.save(); provider.connect(); + logGuard.restore(); if(provider.isConnected()){ LOGGER.log(Level.FINE,"[DB] ---> database connection : success"); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBProvider.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBProvider.java index 43120e0f22..74e04b06af 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBProvider.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBProvider.java @@ -4,6 +4,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.jlab.logging.SplitLogManager; +import org.jlab.logging.LogLevelGuard; import org.rcdb.RCDB; import org.rcdb.Condition; @@ -38,6 +39,7 @@ public Double getSolenoidScale(int run) { static { SplitLogManager.configureHandlers(LOGGER, false); } + private LogLevelGuard logGuard = new LogLevelGuard("org.freehep.math.minuit"); public static final String DEFAULTADDRESS = "mysql://rcdb@clasdb.jlab.org/rcdb"; @@ -89,7 +91,9 @@ private void initialize(String address){ provider = RCDB.createProvider(address); try { LOGGER.log(Level.FINE,"[RCDB] ---> open connection with : " + address); + logGuard.save(); provider.connect(); + logGuard.restore(); } catch (Exception e) { LOGGER.log(Level.SEVERE,"",e); diff --git a/common-tools/clas-logging/src/main/java/org/jlab/logging/LogLevelGuard.java b/common-tools/clas-logging/src/main/java/org/jlab/logging/LogLevelGuard.java new file mode 100644 index 0000000000..effa09372d --- /dev/null +++ b/common-tools/clas-logging/src/main/java/org/jlab/logging/LogLevelGuard.java @@ -0,0 +1,39 @@ +package org.jlab.logging; + +import java.util.List; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Kluge around certain upstream function calls that alter log levels against our will. + * @author dilks + */ +public class LogLevelGuard { + + private final List loggerNames; + private final Map savedLevels = new HashMap<>(); + + /** + * constructor + * @param loggerNames the names of the Loggers to guard + */ + public LogLevelGuard(String... loggerNames) { + this.loggerNames = List.of(loggerNames); + } + + /** save the log levels */ + public void save() { + for(var name : loggerNames) + savedLevels.put(name, Logger.getLogger(name).getLevel()); + } + + /** restore the log levels */ + public void restore() { + for(var entry : savedLevels.entrySet()) + if(entry.getValue() != null) + Logger.getLogger(entry.getKey()).setLevel(entry.getValue()); + } + +}