diff --git a/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt index e800b8d..97c81df 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt @@ -19,6 +19,7 @@ package de.staropensource.engine.base +import de.staropensource.engine.base.Engine.Companion.logger import de.staropensource.engine.base.implementable.ShutdownHandler import de.staropensource.engine.base.implementable.logging.CrashCategory import de.staropensource.engine.base.implementable.logging.FormatBuilder @@ -46,6 +47,7 @@ class EngineConfiguration private constructor() { * * @since v1-alpha10 */ + @Suppress("UNCHECKED_CAST") companion object { // -----> Core engine /** @@ -54,7 +56,7 @@ class EngineConfiguration private constructor() { * * @since v1-alpha10 */ - val timezone: TimeZone = TimeZone.UTC + var timezone: TimeZone = TimeZone.UTC /** * Controls how the engine should shut down. @@ -87,7 +89,7 @@ class EngineConfiguration private constructor() { Level.INFORMATIONAL, Level.WARNING, Level.ERROR, - Level.CRASH + Level.CRASH, ) /** @@ -184,7 +186,67 @@ class EngineConfiguration private constructor() { * @since v1-alpha10 */ @JvmStatic - @Suppress("UNCHECKED_CAST") var logFormatBuilder: KClass = SOSLSv2FormatBuilder::class as KClass + + + // -----> Management methods + /** + * Resets either the specified + * setting or all settings to + * their default value(s). + * + * @param setting name of the setting to reset + * @since v1-alpha10 + */ + fun toDefault(setting: String? = null) { + if (setting == null) { + toDefault("timezone") + toDefault("shutdownHandler") + toDefault("logMode") + toDefault("logLevels") + toDefault("logFeatures") + toDefault("logThreadingPollDelay") + toDefault("logChannelSettings") + toDefault("logCrashCategories") + toDefault("logThreadingHandler") + toDefault("logFormatBuilder") + } else + when (setting) { + "timezone" -> timezone = TimeZone.UTC + "shutdownHandler" -> shutdownHandler = KotlinShutdownHandler.instance + "logMode" -> logMode = OperationMode.NORMAL + "logLevels" -> logLevels = mutableSetOf( + Level.INFORMATIONAL, + Level.WARNING, + Level.ERROR, + Level.CRASH, + ) + "logFeatures" -> logFeatures = mutableSetOf( + Feature.FORMATTING, + Feature.TIME, + Feature.LEVEL, + Feature.ORIGIN, + Feature.LINE_NUMBER, + ) + "logThreadingPollDelay" -> logThreadingPollDelay = 5 + "logChannelSettings" -> logChannelSettings = mutableMapOf( + Pair("engine-core", ChannelSettings( + enable = null, + sanitizeMessage = true, + permitFormatting = true, + applicationName = "The StarOpenSource Engine", + formatter = null, + adapters = null + )) + ) + "logCrashCategories" -> logCrashCategories = linkedSetOf( + InfoCrashCategory.instance, + EngineCrashCategory.instance + ) + "logThreadingHandler" -> logThreadingHandler = null + "logFormatBuilder" -> logFormatBuilder = SOSLSv2FormatBuilder::class as KClass + else -> logger.error("Unable to reset unknown setting '${setting}'") + } + } } } diff --git a/dist/detekt.yml b/dist/detekt.yml index 692df6e..abb3b23 100644 --- a/dist/detekt.yml +++ b/dist/detekt.yml @@ -48,3 +48,5 @@ style: active: false WildcardImport: active: false + MagicNumber: + active: false