mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Added the ability to tune the logger
This commit is contained in:
5
.idea/workspace.xml
generated
5
.idea/workspace.xml
generated
@@ -5,7 +5,10 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="997b32da-b4d4-48ac-ab51-52d65f364f81" name="Changes" comment="">
|
<list default="true" id="997b32da-b4d4-48ac-ab51-52d65f364f81" name="Changes" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/Logging.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/Logging.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/Logging.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/Logging.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/Main.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/eventbus/GlobalEventBus.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/eventbus/GlobalEventBus.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -81,7 +84,7 @@
|
|||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="Main" type="Application" factoryName="Application" nameIsGenerated="true">
|
<configuration name="Main" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||||
<option name="MAIN_CLASS_NAME" value="org.toop.Main" />
|
<option name="MAIN_CLASS_NAME" value="org.toop.Main" />
|
||||||
<module name="pism" />
|
<module name="pis" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
<pattern>
|
<pattern>
|
||||||
<option name="PATTERN" value="org.toop.*" />
|
<option name="PATTERN" value="org.toop.*" />
|
||||||
|
|||||||
@@ -11,19 +11,64 @@ import org.toop.eventbus.EventRegistry;
|
|||||||
* Options for logging.
|
* Options for logging.
|
||||||
*/
|
*/
|
||||||
public final class Logging {
|
public final class Logging {
|
||||||
public static void disableLogs() {
|
public static void disableAllLogs() {
|
||||||
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||||
Configuration config = ctx.getConfiguration();
|
Configuration config = ctx.getConfiguration();
|
||||||
LoggerConfig loggerConfig = config.getLoggerConfig(EventRegistry.class.getName());
|
LoggerConfig rootLoggerConfig = config.getRootLogger();
|
||||||
loggerConfig.setLevel(Level.OFF);
|
rootLoggerConfig.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();
|
ctx.updateLoggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void enableAllLogs(Level level) {
|
||||||
|
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||||
|
Configuration config = ctx.getConfiguration();
|
||||||
|
LoggerConfig rootLoggerConfig = config.getRootLogger();
|
||||||
|
rootLoggerConfig.setLevel(level);
|
||||||
|
ctx.updateLoggers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void disableLogsForClass(Class<T> class_) {
|
||||||
|
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||||
|
Configuration config = ctx.getConfiguration();
|
||||||
|
LoggerConfig specificConfig = new LoggerConfig(class_.getName(), Level.OFF, true);
|
||||||
|
config.addLogger(class_.getName(), specificConfig);
|
||||||
|
ctx.updateLoggers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void enableLogsForClass(Class<T> class_, Level levelToLog) {
|
||||||
|
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
|
||||||
|
Configuration config = ctx.getConfiguration();
|
||||||
|
LoggerConfig loggerConfig = config.getLoggers().get(class_.getName());
|
||||||
|
if (loggerConfig == null) {
|
||||||
|
loggerConfig = new LoggerConfig(class_.getName(), levelToLog, true);
|
||||||
|
config.addLogger(class_.getName(), loggerConfig);
|
||||||
|
} else {
|
||||||
|
loggerConfig.setLevel(levelToLog);
|
||||||
|
}
|
||||||
|
ctx.updateLoggers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void enableAllLogsForClass(Class<T> class_) {
|
||||||
|
enableLogsForClass(class_, Level.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void enableDebugLogsForClass(Class<T> class_) {
|
||||||
|
enableLogsForClass(class_, Level.DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void enableErrorLogsForClass(Class<T> class_) {
|
||||||
|
enableLogsForClass(class_, Level.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void enableFatalLogsForClass(Class<T> class_) {
|
||||||
|
enableLogsForClass(class_, Level.FATAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void enableInfoLogsForClass(Class<T> class_) {
|
||||||
|
enableLogsForClass(class_, Level.INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void enableTraceLogsForClass(Class<T> class_) {
|
||||||
|
enableLogsForClass(class_, Level.TRACE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.toop;
|
package org.toop;
|
||||||
|
|
||||||
import org.toop.UI.GameSelectorWindow;
|
import org.toop.UI.GameSelectorWindow;
|
||||||
|
import org.toop.eventbus.EventRegistry;
|
||||||
import org.toop.eventbus.Events;
|
import org.toop.eventbus.Events;
|
||||||
import org.toop.eventbus.GlobalEventBus;
|
import org.toop.eventbus.GlobalEventBus;
|
||||||
import org.toop.server.backend.ServerManager;
|
import org.toop.server.backend.ServerManager;
|
||||||
@@ -16,6 +17,8 @@ public class Main {
|
|||||||
private static boolean running = false;
|
private static boolean running = false;
|
||||||
|
|
||||||
public static void main(String[] args) throws ExecutionException, InterruptedException {
|
public static void main(String[] args) throws ExecutionException, InterruptedException {
|
||||||
|
// Logging.disableAllLogs();
|
||||||
|
// Logging.enableAllLogsForClass(EventRegistry.class);
|
||||||
initSystems();
|
initSystems();
|
||||||
registerEvents();
|
registerEvents();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user