Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -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<String,String[]> constantContainer = new HashMap<>();
private final boolean PRINT_ALL = true;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> loggerNames;
private final Map<String, Level> 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());
}

}
Loading