Moved disable and enable logging to dedicated class, removed unecessary imports

This commit is contained in:
lieght
2025-09-17 17:48:22 +02:00
parent 4c0e70fc1f
commit 61264a9b43
3 changed files with 38 additions and 32 deletions

View File

@@ -1,24 +1,12 @@
package org.toop;
import org.apache.logging.log4j.Level;
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;
import org.toop.eventbus.Events;
import org.toop.eventbus.GlobalEventBus;
import org.toop.Logging;
import org.toop.server.backend.ServerManager;
import org.toop.server.frontend.ConnectionManager;
import org.toop.server.backend.TcpServer;
import org.toop.game.*;
import org.toop.game.tictactoe.*;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class Main {
@@ -26,7 +14,7 @@ public class Main {
public static void main(String[] args) throws ExecutionException, InterruptedException {
initSystems();
disableLogs();
Logging.disableLogs();
ConsoleGui console = new ConsoleGui();
@@ -42,20 +30,4 @@ public class Main {
new ConnectionManager();
}
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();
}
}