diff --git a/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java b/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java index fcde5388..10e7d508 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java +++ b/base/src/main/java/de/staropensource/sosengine/base/EngineConfiguration.java @@ -24,6 +24,7 @@ import de.staropensource.sosengine.base.classes.Configuration; import de.staropensource.sosengine.base.classes.helpers.EventHelper; import de.staropensource.sosengine.base.logging.CrashHandler; import de.staropensource.sosengine.base.logging.Logger; +import de.staropensource.sosengine.base.types.EngineState; import de.staropensource.sosengine.base.types.logging.LogLevel; import de.staropensource.sosengine.base.types.vectors.Vec2f; import de.staropensource.sosengine.base.utility.parser.PropertyParser; @@ -306,7 +307,13 @@ public final class EngineConfiguration extends Configuration { case "errorShortcodeConverter" -> errorShortcodeConverter = parser.getBoolean(group + property); - case "optimizeLogging" -> optimizeLogging = parser.getBoolean(group + property); + case "optimizeLogging" -> { + optimizeLogging = parser.getBoolean(group + property); + + // Start logging thread automatically + if (optimizeLogging && Engine.getInstance().getState() == EngineState.RUNNING) + Logger.startLoggingThread(); + } case "optimizeEvents" -> optimizeEvents = parser.getBoolean(group + property); case "optimizeSubsystemInitialization" -> optimizeSubsystemInitialization = parser.getBoolean(group + property); diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java b/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java index 37f4017b..baf915ac 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/Logger.java @@ -28,6 +28,7 @@ import de.staropensource.sosengine.base.events.LogEvent; import de.staropensource.sosengine.base.internal.placeholders.logger.*; import de.staropensource.sosengine.base.internal.types.QueuedLogMessage; import de.staropensource.sosengine.base.logging.implementation.PlainLoggerImplementation; +import de.staropensource.sosengine.base.types.EngineState; import de.staropensource.sosengine.base.types.logging.LogLevel; import de.staropensource.sosengine.base.types.logging.LogRule; import de.staropensource.sosengine.base.types.logging.LogRuleType; @@ -126,7 +127,9 @@ public final class Logger { Runnable threadLogic = () -> { while (true) { // Run in loop // Stop thread when engine is shutting down - if (Engine.getInstance().isShuttingDown()) + if (Engine.getInstance().getState() == EngineState.SHUTDOWN + || Engine.getInstance().getState() == EngineState.CRASHED + || !EngineConfiguration.getInstance().isOptimizeLogging()) return; // Process all log messages