Add EngineConfiguration.toDefault method

This commit is contained in:
JeremyStar™ 2024-12-20 01:37:39 +01:00
parent 04f8aa360a
commit e4f4ab6f8c
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 67 additions and 3 deletions

View file

@ -19,6 +19,7 @@
package de.staropensource.engine.base 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.ShutdownHandler
import de.staropensource.engine.base.implementable.logging.CrashCategory import de.staropensource.engine.base.implementable.logging.CrashCategory
import de.staropensource.engine.base.implementable.logging.FormatBuilder import de.staropensource.engine.base.implementable.logging.FormatBuilder
@ -46,6 +47,7 @@ class EngineConfiguration private constructor() {
* *
* @since v1-alpha10 * @since v1-alpha10
*/ */
@Suppress("UNCHECKED_CAST")
companion object { companion object {
// -----> Core engine // -----> Core engine
/** /**
@ -54,7 +56,7 @@ class EngineConfiguration private constructor() {
* *
* @since v1-alpha10 * @since v1-alpha10
*/ */
val timezone: TimeZone = TimeZone.UTC var timezone: TimeZone = TimeZone.UTC
/** /**
* Controls how the engine should shut down. * Controls how the engine should shut down.
@ -87,7 +89,7 @@ class EngineConfiguration private constructor() {
Level.INFORMATIONAL, Level.INFORMATIONAL,
Level.WARNING, Level.WARNING,
Level.ERROR, Level.ERROR,
Level.CRASH Level.CRASH,
) )
/** /**
@ -184,7 +186,67 @@ class EngineConfiguration private constructor() {
* @since v1-alpha10 * @since v1-alpha10
*/ */
@JvmStatic @JvmStatic
@Suppress("UNCHECKED_CAST")
var logFormatBuilder: KClass<FormatBuilder> = SOSLSv2FormatBuilder::class as KClass<FormatBuilder> var logFormatBuilder: KClass<FormatBuilder> = SOSLSv2FormatBuilder::class as KClass<FormatBuilder>
// -----> 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<FormatBuilder>
else -> logger.error("Unable to reset unknown setting '${setting}'")
}
}
} }
} }

2
dist/detekt.yml vendored
View file

@ -48,3 +48,5 @@ style:
active: false active: false
WildcardImport: WildcardImport:
active: false active: false
MagicNumber:
active: false