Implement logic for logging thread control

The logging thread now automatically starts or shuts down based on EngineConfiguration#optimizeLogging and Engine#state == EngineState.RUNNING
This commit is contained in:
JeremyStar™ 2024-07-31 15:02:29 +02:00
parent bd70b17236
commit c984974252
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 12 additions and 2 deletions

View file

@ -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);

View file

@ -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