mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Moved disable and enable logging to dedicated class, removed unecessary imports
This commit is contained in:
26
src/main/java/org/toop/Logging.java
Normal file
26
src/main/java/org/toop/Logging.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.toop;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
import org.apache.logging.log4j.core.config.LoggerConfig;
|
||||
import org.toop.eventbus.EventRegistry;
|
||||
|
||||
public final class Logging {
|
||||
public static void disableLogs() {
|
||||
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
Configuration config = ctx.getConfiguration();
|
||||
LoggerConfig loggerConfig = config.getLoggerConfig(EventRegistry.class.getName());
|
||||
loggerConfig.setLevel(Level.OFF);
|
||||
ctx.updateLoggers(); // apply changes immediately
|
||||
}
|
||||
|
||||
public static void enableLogs(Level level) {
|
||||
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||
Configuration config = ctx.getConfiguration();
|
||||
LoggerConfig loggerConfig = config.getLoggerConfig(EventRegistry.class.getName());
|
||||
loggerConfig.setLevel(level);
|
||||
ctx.updateLoggers();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user