Skip to content

Commit 83f9ff3

Browse files
committed
fix: don't let SplitLogManager do anything if it's not the manager
1 parent a7afa46 commit 83f9ff3

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/DatabaseConstantProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private void initialize(String address){
148148

149149
LOGGER.log(Level.INFO, String.format("[DB] ---> open %s | %s | %s | %s", runNumber, variation, databaseDate, address));
150150

151-
provider.connect();
151+
provider.connect(); // FIXME: this function call resets log levels, e.g. of jminuit
152152

153153
if(provider.isConnected()){
154154
LOGGER.log(Level.FINE,"[DB] ---> database connection : success");

common-tools/clas-logging/src/main/java/org/jlab/logging/SplitLogManager.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
*/
1111
public class SplitLogManager extends LogManager {
1212

13+
/** whether or not this manager is managing */
14+
private static final boolean isManaging = SplitLogManager.class.getName().equals(System.getProperty("java.util.logging.manager"));
15+
1316
/**
1417
* create a new {@link Logger} instance
1518
* @param name the name of the logger
1619
* @return a new {@link Logger} instance
1720
*/
1821
@Override
1922
public Logger getLogger(String name) {
23+
warnIfNotManaging("getLogger");
2024
Logger logger = super.getLogger(name);
2125
if(logger != null)
2226
configureHandlers(logger, true);
@@ -30,6 +34,7 @@ public Logger getLogger(String name) {
3034
*/
3135
@Override
3236
public synchronized boolean addLogger(Logger logger) {
37+
warnIfNotManaging("addLogger");
3338
boolean added = super.addLogger(logger);
3439
if(added)
3540
configureHandlers(logger, true);
@@ -43,6 +48,10 @@ public synchronized boolean addLogger(Logger logger) {
4348
*/
4449
public static void configureHandlers(Logger logger, boolean includePrefix) {
4550

51+
// do nothing, if `SplitLogManager` is not the log manager
52+
// if(!isManaging)
53+
// return;
54+
4655
// clear handlers
4756
logger.setUseParentHandlers(false);
4857
for(var handler : logger.getHandlers())
@@ -121,9 +130,21 @@ else if(SplitLogManagerConfig.INSTANCE.defaultLevelWasSet())
121130
* @param level the {@code Level} to apply
122131
*/
123132
public static void configureLevel(Logger logger, Level level) {
133+
// if(!isManaging)
134+
// return;
135+
warnIfNotManaging("configureLevel");
124136
logger.setLevel(level);
125137
for(var handler : logger.getHandlers())
126138
handler.setLevel(level);
127139
}
128140

141+
/**
142+
* warn, if this log manager is not the manager
143+
* @param src the source of the warning, such as a function name
144+
*/
145+
private static void warnIfNotManaging(String src) {
146+
if(!isManaging)
147+
System.err.println("WARNING: SplitLogManager is not the LogManager, but its '" + src + "' was called");
148+
}
149+
129150
}

0 commit comments

Comments
 (0)