Added a quick function to disable logs

This commit is contained in:
lieght
2025-09-17 17:44:50 +02:00
parent 38ea15738c
commit 23e0ee6c62
3 changed files with 31 additions and 3 deletions

5
.idea/workspace.xml generated
View File

@@ -6,7 +6,8 @@
<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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/toop/ConsoleGui.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/ConsoleGui.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/EventRegistry.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/toop/eventbus/EventRegistry.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" />
@@ -83,7 +84,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="5345000" /> <workItem from="1758117515668" duration="5942000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@@ -1,5 +1,10 @@
package org.toop; 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.Events;
import org.toop.eventbus.GlobalEventBus; import org.toop.eventbus.GlobalEventBus;
import org.toop.server.backend.ServerManager; import org.toop.server.backend.ServerManager;
@@ -21,6 +26,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();
ConsoleGui console = new ConsoleGui(); ConsoleGui console = new ConsoleGui();
@@ -35,4 +41,21 @@ public class Main {
new ServerManager(); new ServerManager();
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();
}
} }

View File

@@ -2,7 +2,11 @@ package org.toop.eventbus;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.toop.Main; 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 java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;