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

12
.idea/workspace.xml generated
View File

@@ -5,14 +5,22 @@
</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 afterPath="$PROJECT_DIR$/src/main/java/org/toop/Logging.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <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/eventbus/EventRegistry.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/eventbus/EventRegistry.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" />
</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" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
@@ -83,7 +91,7 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1758117514311</updated> <updated>1758117514311</updated>
<workItem from="1758117515668" duration="5965000" /> <workItem from="1758117515668" duration="6137000" />
</task> </task>
<servers /> <servers />
</component> </component>

View 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();
}
}

View File

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