Skip to content
Draft
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 @@ -148,7 +148,7 @@ private void initialize(String address){

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

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

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 @@ -10,13 +10,17 @@
*/
public class SplitLogManager extends LogManager {

/** whether or not this manager is managing */
private static final boolean isManaging = SplitLogManager.class.getName().equals(System.getProperty("java.util.logging.manager"));

/**
* create a new {@link Logger} instance
* @param name the name of the logger
* @return a new {@link Logger} instance
*/
@Override
public Logger getLogger(String name) {
warnIfNotManaging("getLogger");
Logger logger = super.getLogger(name);
if(logger != null)
configureHandlers(logger, true);
Expand All @@ -30,6 +34,7 @@ public Logger getLogger(String name) {
*/
@Override
public synchronized boolean addLogger(Logger logger) {
warnIfNotManaging("addLogger");
boolean added = super.addLogger(logger);
if(added)
configureHandlers(logger, true);
Expand All @@ -43,6 +48,10 @@ public synchronized boolean addLogger(Logger logger) {
*/
public static void configureHandlers(Logger logger, boolean includePrefix) {

// do nothing, if `SplitLogManager` is not the log manager
if(!isManaging)
return;

// clear handlers
logger.setUseParentHandlers(false);
for(var handler : logger.getHandlers())
Expand Down Expand Up @@ -121,9 +130,21 @@ else if(SplitLogManagerConfig.INSTANCE.defaultLevelWasSet())
* @param level the {@code Level} to apply
*/
public static void configureLevel(Logger logger, Level level) {
if(!isManaging)
return;
warnIfNotManaging("configureLevel");
logger.setLevel(level);
for(var handler : logger.getHandlers())
handler.setLevel(level);
}

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

}
Loading