diff --git a/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt b/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt index 57226c31b..a98224fca 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt @@ -23,7 +23,7 @@ package de.staropensource.engine.base import de.staropensource.engine.base.exception.EngineInitializationFailureException import de.staropensource.engine.base.utility.Environment import de.staropensource.engine.base.utility.FileAccess -import de.staropensource.engine.logging.Logger +import de.staropensource.engine.base.logging.Logger /** * Primary class of the engine. @@ -53,7 +53,7 @@ class Engine private constructor() { * @since v1-alpha10 */ var state: State = State.UNINITIALIZED - private set + internal set /** * Contains if the engine is currently @@ -143,24 +143,77 @@ class Engine private constructor() { /** * Shuts the engine down. * - * @throws Throwable on shutdown error * @since v1-alpha10 */ @JvmStatic - @Throws(Throwable::class) fun shutdown() { // Abort if not initialized if (state != State.INITIALIZED) return - state = State.SHUTTING_DOWN logger.info("Shutting down") + // Perform shutdown + performShutdown() + state = State.SHUT_DOWN + } + + /** + * Shuts the engine down and + * terminates the application. + * + * @since v1-alpha10 + */ + @JvmStatic + fun shutdownFinal(exitcode: UByte = 0u) { + // Abort if not initialized + if (state != State.INITIALIZED) + return + + logger.info("Shutting down for good") + + // Perform shutdown + performShutdown() + state = State.SHUT_DOWN + + // Quit application + EngineConfiguration.shutdownHandler.exit(exitcode) + } + + /** + * Shuts the engine down after + * it having crashed fatally. + * + * @since v1-alpha10 + */ + @JvmStatic + internal fun shutdownAfterCrash() { + logger.info("Shutting down after having crashed fatally") + + // Perform shutdown + performShutdown(crashed = true) + state = State.CRASHED + + // Quit application + EngineConfiguration.shutdownHandler.exit(exitcode = 69u) + } + + /** + * Shuts the engine down. + * + * This performs the actual shutdown, + * just without the bloat. + * + * @param crashed enables super careful mode to prevent further breakage + * @since v1-alpha10 + */ + @JvmStatic + private fun performShutdown(crashed: Boolean = false) { + state = State.SHUTTING_DOWN + // Run shutdown code Environment.unset() FileAccess.unsetDefaultPaths() - - state = State.SHUT_DOWN } } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt new file mode 100644 index 000000000..3a1921296 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt @@ -0,0 +1,175 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU Affero General Public License v3 + * with an exception allowing classpath linking. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.engine.base + +import de.staropensource.engine.base.implementable.ShutdownHandler +import de.staropensource.engine.base.implementable.logging.CrashCategory +import de.staropensource.engine.base.implementable.logging.FormatBuilder +import de.staropensource.engine.base.implementation.logging.KotlinShutdownHandler +import de.staropensource.engine.base.implementation.logging.crashcategory.InfoCrashCategory +import de.staropensource.engine.base.implementation.logging.formatbuilder.SOSLSv2FormatBuilder +import de.staropensource.engine.base.logging.Logger +import de.staropensource.engine.base.logging.LoggerThreadingHandler +import de.staropensource.engine.base.type.logging.ChannelSettings +import de.staropensource.engine.base.type.logging.Feature +import de.staropensource.engine.base.type.logging.Level +import de.staropensource.engine.base.type.logging.OperationMode +import kotlinx.datetime.TimeZone +import kotlin.reflect.KClass + +/** + * Provides the engine configuration. + * + * @since v1-alpha10 + */ +class EngineConfiguration private constructor() { + /** + * Companion object of [EngineConfiguration]. + * + * @since v1-alpha10 + */ + companion object { + // -----> Core engine + /** + * Controls which [TimeZone] to use + * for date and time synchronization. + * + * @since v1-alpha10 + */ + val timezone: TimeZone = TimeZone.UTC + + /** + * Controls how the engine should shut down. + * + * @since v1-alpha10 + */ + @JvmStatic + var shutdownHandler: ShutdownHandler = KotlinShutdownHandler.instance + + + // -----> Logging system + /** + * Controls how [Logger] + * instances should function. + * + * @since v1-alpha10 + */ + @JvmStatic + var logMode: OperationMode = OperationMode.NORMAL + + /** + * Determines which levels are + * allowed to be processed by + * the logging system. + * + * @since v1-alpha10 + */ + @JvmStatic + var logLevels: MutableSet = mutableSetOf( + Level.INFORMATIONAL, + Level.WARNING, + Level.ERROR, + Level.CRASH + ) + + /** + * Determines which enabled log + * features shall be displayed + * in the final log output. + * + * @since v1-alpha10 + */ + @JvmStatic + var logFeatures: MutableSet = mutableSetOf( + Feature.FORMATTING, + Feature.TIME, + Feature.LEVEL, + Feature.ORIGIN, + Feature.LINE_NUMBER, + ) + + /** + * Controls how fast the [LoggerThreadingHandler] + * shall wait until processing the log queue after + * it has been processed minus the processing time. + * + * This only takes effect if [logThreadingHandler] + * is not set to `null`. + * + * @since v1-alpha10 + */ + @JvmStatic + var logThreadingPollDelay: Int = 5 + + /** + * Holds log channel settings. + * + * These control how different + * log channels behave. + * + * @since v1-alpha10 + */ + @JvmStatic + var logChannelSettings: MutableMap = mutableMapOf() + + /** + * Holds all registered [CrashCategory]s + * used by the logging system. + * + * These are used to build crash reports + * and supply information about a crash. + * + * @since v1-alpha10 + */ + @JvmStatic + var logCrashCategories: LinkedHashSet = linkedSetOf( + InfoCrashCategory.instance + ) + + /** + * Controls the [LoggerThreadingHandler] + * to use for logging. + * + * This determines how multithreading is + * handled in the logging system. Set to + * `null` for a single-threaded logger. + * + * @see LoggerThreadingHandler + * @since v1-alpha10 + */ + @JvmStatic + var logThreadingHandler: LoggerThreadingHandler? = null + + /** + * Controls the [FormatBuilder] to use. + * + * These design the log output and + * will determine how the final + * log output will look like. + * + * @see FormatBuilder + * @since v1-alpha10 + */ + @JvmStatic + @Suppress("UNCHECKED_CAST") + var logFormatBuilder: KClass = SOSLSv2FormatBuilder::class as KClass + } +} diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/ShutdownHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/ShutdownHandler.kt similarity index 92% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/ShutdownHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/ShutdownHandler.kt index 8d1ff288f..a35f60078 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/ShutdownHandler.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/ShutdownHandler.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable /** * Handles shutdowns. @@ -32,5 +32,5 @@ interface ShutdownHandler { * @param exitcode the code to exit with * @since v1-alpha10 */ - fun exit(exitcode: Byte = 0) + fun exit(exitcode: UByte = 0u) } diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/Adapter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt similarity index 91% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/Adapter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt index d19a4424f..2d0cb486a 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/Adapter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt @@ -18,9 +18,9 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable.logging -import de.staropensource.engine.logging.type.Call +import de.staropensource.engine.base.type.logging.Call /** * Handles processed log calls. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/CrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/CrashCategory.kt similarity index 89% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/CrashCategory.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/CrashCategory.kt index cd7b8e368..121db1ab8 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/CrashCategory.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/CrashCategory.kt @@ -18,11 +18,11 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable.logging -import de.staropensource.engine.logging.CrashHandler -import de.staropensource.engine.logging.type.Call -import de.staropensource.engine.logging.type.ChannelSettings +import de.staropensource.engine.base.logging.CrashHandler +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.ChannelSettings /** * Used by the [CrashHandler] to diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/Filter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Filter.kt similarity index 91% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/Filter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Filter.kt index e51bc4b8b..4760efb91 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/Filter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Filter.kt @@ -18,9 +18,9 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable.logging -import de.staropensource.engine.logging.type.Call +import de.staropensource.engine.base.type.logging.Call /** * Provides methods for filtering log calls. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt similarity index 92% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/FormatBuilder.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt index bef69a8de..369f44868 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/FormatBuilder.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable.logging -import de.staropensource.engine.logging.type.Call -import de.staropensource.engine.logging.type.Feature +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.Feature /** * Builds log formats. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/Formatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Formatter.kt similarity index 96% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/Formatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Formatter.kt index 1a67f059a..c31543ab6 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/Formatter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Formatter.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable.logging /** * Provides log format formatting. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/OneCycleFormatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/OneCycleFormatter.kt similarity index 96% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/OneCycleFormatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/OneCycleFormatter.kt index 7fe638f29..a089b7440 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/OneCycleFormatter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/OneCycleFormatter.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable.logging /** * Performs message formatting in one cycle. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/TwoCycleFormatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/TwoCycleFormatter.kt similarity index 97% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/TwoCycleFormatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/TwoCycleFormatter.kt index c7f6546b1..42116993e 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/TwoCycleFormatter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/TwoCycleFormatter.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.implementable.logging /** * Performs message formatting in two cycles. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/TwoCycleFormatterImpl.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/TwoCycleFormatterImpl.kt similarity index 96% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/TwoCycleFormatterImpl.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/TwoCycleFormatterImpl.kt index 5bf740755..9ec4591a6 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/TwoCycleFormatterImpl.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/TwoCycleFormatterImpl.kt @@ -18,9 +18,9 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementation +package de.staropensource.engine.base.implementable.logging -import de.staropensource.engine.logging.implementable.TwoCycleFormatter +import kotlin.text.iterator /** * A [TwoCycleFormatter] implementation providing diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/package-info.kt similarity index 87% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/package-info.kt index ae7de0d8b..cd521ab76 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/package-info.kt @@ -19,9 +19,9 @@ */ /** - * Implementations of various - * interfaces and abstract classes. + * Interfaces and abstract classes + * used by the logging system. * * @since v1-alpha10 */ -package de.staropensource.engine.logging.implementation; +package de.staropensource.engine.base.implementable.logging diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/KotlinShutdownHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt similarity index 87% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/KotlinShutdownHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt index 992f416d6..021d47363 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/KotlinShutdownHandler.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt @@ -18,14 +18,14 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementation +package de.staropensource.engine.base.implementation.logging -import de.staropensource.engine.logging.implementable.ShutdownHandler +import de.staropensource.engine.base.implementable.ShutdownHandler import kotlin.system.exitProcess /** * [ShutdownHandler] implementation using - * Kotlin's [kotlin.system.exitProcess] method. + * Kotlin's [exitProcess] method. * * @since v1-alpha10 */ @@ -45,7 +45,7 @@ class KotlinShutdownHandler private constructor() : ShutdownHandler { val instance: KotlinShutdownHandler = KotlinShutdownHandler() } - override fun exit(exitcode: Byte) { + override fun exit(exitcode: UByte) { exitProcess(exitcode.toInt()) } } diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/NoOperationFormatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt similarity index 95% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/NoOperationFormatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt index 79eba3f86..d65fe3916 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/NoOperationFormatter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt @@ -18,9 +18,10 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementation +package de.staropensource.engine.base.implementation.logging -import de.staropensource.engine.logging.implementable.OneCycleFormatter +import de.staropensource.engine.base.implementable.logging.OneCycleFormatter +import kotlin.text.iterator /** * Swallows all formatting tags diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/FileWriteAdapter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/FileWriteAdapter.kt new file mode 100644 index 000000000..f07d492c6 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/FileWriteAdapter.kt @@ -0,0 +1,38 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU Affero General Public License v3 + * with an exception allowing classpath linking. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.engine.base.implementation.logging.adapter + +import de.staropensource.engine.base.implementable.logging.Adapter +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.utility.FileAccess + +/** + * [Adapter] for writing log + * output to the specific file. + * + * @see Adapter + * @since v1-alpha10 + */ +open class FileWriteAdapter(var location: FileAccess): Adapter { + override fun handle(call: Call, format: String) { + location.appendString("\n${format}") + } +} diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/PrintlnAdapter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt similarity index 84% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/PrintlnAdapter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt index 1c8a12f31..e42659c7c 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/PrintlnAdapter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt @@ -18,14 +18,14 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementation +package de.staropensource.engine.base.implementation.logging.adapter -import de.staropensource.engine.logging.implementable.Adapter -import de.staropensource.engine.logging.type.Call +import de.staropensource.engine.base.implementable.logging.Adapter +import de.staropensource.engine.base.type.logging.Call /** - * Uses Kotlin's [println] - * method to print log messages. + * [Adapter] for printing messages + * using Kotlin's [println] method. * * @see Adapter * @since v1-alpha10 diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/package-info.kt similarity index 83% rename from base/src/main/kotlin/de/staropensource/engine/logging/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/package-info.kt index 44051870e..59c7533d6 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/package-info.kt @@ -19,8 +19,10 @@ */ /** - * StarOpenSource's logging system. + * Implementations of the [Adapter] interface. * * @since v1-alpha10 */ -package de.staropensource.engine.logging; +package de.staropensource.engine.base.implementation.logging.adapter + +import de.staropensource.engine.base.implementable.logging.Adapter diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/crashcategory/InfoCrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt similarity index 89% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/crashcategory/InfoCrashCategory.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt index 1223a23c5..5f12d45d1 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/crashcategory/InfoCrashCategory.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt @@ -18,11 +18,11 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementation.crashcategory +package de.staropensource.engine.base.implementation.logging.crashcategory -import de.staropensource.engine.logging.implementable.CrashCategory -import de.staropensource.engine.logging.type.Call -import de.staropensource.engine.logging.type.ChannelSettings +import de.staropensource.engine.base.implementable.logging.CrashCategory +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.ChannelSettings /** * [CrashCategory] implementation diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/crashcategory/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/package-info.kt similarity index 86% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/crashcategory/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/package-info.kt index 57d2b4c8b..e69523b83 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/crashcategory/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/package-info.kt @@ -23,6 +23,6 @@ * * @since v1-alpha10 */ -package de.staropensource.engine.logging.implementation.crashcategory +package de.staropensource.engine.base.implementation.logging.crashcategory -import de.staropensource.engine.logging.implementable.CrashCategory +import de.staropensource.engine.base.implementable.logging.CrashCategory diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/SOSLSv2FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt similarity index 85% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementation/SOSLSv2FormatBuilder.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt index a9a17481a..65c286833 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementation/SOSLSv2FormatBuilder.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt @@ -18,14 +18,14 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.implementation +package de.staropensource.engine.base.implementation.logging.formatbuilder -import de.staropensource.engine.logging.Logger -import de.staropensource.engine.logging.LoggerConfiguration -import de.staropensource.engine.logging.type.Call -import de.staropensource.engine.logging.type.Feature -import de.staropensource.engine.logging.implementable.FormatBuilder -import de.staropensource.engine.logging.type.Level +import de.staropensource.engine.base.EngineConfiguration +import de.staropensource.engine.base.logging.Logger +import de.staropensource.engine.base.implementable.logging.FormatBuilder +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.Feature +import de.staropensource.engine.base.type.logging.Level import kotlinx.datetime.Clock import kotlinx.datetime.LocalDateTime import kotlinx.datetime.toLocalDateTime @@ -40,7 +40,7 @@ import kotlinx.datetime.toLocalDateTime * @param call [Call] to build a format for * @since v1-alpha10 */ -class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { +open class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { override fun toString(): String { val format: StringBuilder = StringBuilder() @@ -69,11 +69,11 @@ class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { * @param format [StringBuilder] to operate on * @since v1-alpha10 */ - private fun addRuntime(format: StringBuilder) { + protected fun addRuntime(format: StringBuilder) { if (enabledFeatures.contains(Feature.RUNTIME)) format .append("[") - .append(Logger.initializationTime) + .append(Logger.Companion.initializationTime) .append("ms") .append("] ") } @@ -84,8 +84,8 @@ class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { * @param format [StringBuilder] to operate on * @since v1-alpha10 */ - private fun addDateTime(format: StringBuilder) { - val datetime: LocalDateTime = Clock.System.now().toLocalDateTime(LoggerConfiguration.featureDateTimeTZ) + protected fun addDateTime(format: StringBuilder) { + val datetime: LocalDateTime = Clock.System.now().toLocalDateTime(EngineConfiguration.timezone) if (enabledFeatures.contains(Feature.DATE) || enabledFeatures.contains(Feature.TIME)) format.append("[") @@ -115,7 +115,7 @@ class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { * @param format [StringBuilder] to operate on * @since v1-alpha10 */ - private fun addLevel(format: StringBuilder) { + protected fun addLevel(format: StringBuilder) { if (enabledFeatures.contains(Feature.LEVEL)) format.append( when (call.level) { @@ -138,7 +138,7 @@ class SOSLSv2FormatBuilder(call: Call) : FormatBuilder(call) { * @param format [StringBuilder] to operate on * @since v1-alpha10 */ - private fun addOriginAndMetadata(format: StringBuilder) { + protected fun addOriginAndMetadata(format: StringBuilder) { if (enabledFeatures.contains(Feature.ORIGIN)) { format.append(call.origin) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/package-info.kt new file mode 100644 index 000000000..e99e395bf --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/package-info.kt @@ -0,0 +1,28 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU Affero General Public License v3 + * with an exception allowing classpath linking. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/** + * Implementations of the [FormatBuilder] abstract class. + * + * @since v1-alpha10 + */ +package de.staropensource.engine.base.implementation.logging.formatbuilder + +import de.staropensource.engine.base.implementable.logging.FormatBuilder diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/package-info.kt new file mode 100644 index 000000000..4580c12c5 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/package-info.kt @@ -0,0 +1,29 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU Affero General Public License v3 + * with an exception allowing classpath linking. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/** + * Implementations of various + * interfaces and abstract classes + * found in the [de.staropensource.engine.base.implementable.logging] + * package of the logging system. + * + * @since v1-alpha10 + */ +package de.staropensource.engine.base.implementation.logging diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/CrashHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/CrashHandler.kt similarity index 82% rename from base/src/main/kotlin/de/staropensource/engine/logging/CrashHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/CrashHandler.kt index 1583606dd..7add02f76 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/CrashHandler.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/CrashHandler.kt @@ -18,14 +18,15 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging +package de.staropensource.engine.base.logging -import de.staropensource.engine.logging.implementable.Adapter -import de.staropensource.engine.logging.implementable.CrashCategory -import de.staropensource.engine.logging.implementable.Formatter -import de.staropensource.engine.logging.implementation.KotlinShutdownHandler -import de.staropensource.engine.logging.type.Call -import de.staropensource.engine.logging.type.ChannelSettings +import de.staropensource.engine.base.Engine +import de.staropensource.engine.base.EngineConfiguration +import de.staropensource.engine.base.implementable.logging.Adapter +import de.staropensource.engine.base.implementable.logging.CrashCategory +import de.staropensource.engine.base.implementable.logging.Formatter +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.ChannelSettings /** * Handles crashes. @@ -50,7 +51,9 @@ class CrashHandler private constructor() { internal fun handle(call: Call, throwable: Throwable? = null, fatal: Boolean = true) { val format: StringBuilder = StringBuilder() var formatFinalized: String? = null - val channelconf: ChannelSettings? = LoggerConfiguration.channelSettings[call.channel] + val channelconf: ChannelSettings? = EngineConfiguration.logChannelSettings[call.channel] + + Engine.state = Engine.State.CRASHED if (ChannelSettings.getSetting(channelconf, "permitFormatting") as Boolean) format.append("") @@ -60,7 +63,7 @@ class CrashHandler private constructor() { .append(ChannelSettings.getSetting(channelconf, "applicationName")) .append(" crashed!\nIf you're a user of this application, then please report this crash to the developer.") - for (category: CrashCategory in LoggerConfiguration.crashCategories) + for (category: CrashCategory in EngineConfiguration.logCrashCategories) if (category.check()) format .append("\n\n${category.getName()}") @@ -78,11 +81,13 @@ class CrashHandler private constructor() { else format.toString() - // Pass format to adapter - (ChannelSettings.getSetting(channelconf, "adapter") as Adapter).handle(call, formatFinalized) + // Pass format to adapters + @Suppress("UNCHECKED_CAST") + for (adapter: Adapter in ChannelSettings.getSetting(channelconf, "adapters") as Set) + adapter.handle(call, formatFinalized) if (fatal) - (LoggerConfiguration.shutdownHandler ?: KotlinShutdownHandler.instance).exit(exitcode = 69) + Engine.shutdownAfterCrash() } /** diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/Filterer.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Filterer.kt similarity index 91% rename from base/src/main/kotlin/de/staropensource/engine/logging/Filterer.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/Filterer.kt index cd8dc64c2..9db82aa5c 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/Filterer.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Filterer.kt @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging +package de.staropensource.engine.base.logging -import de.staropensource.engine.logging.implementable.Filter -import de.staropensource.engine.logging.type.Call +import de.staropensource.engine.base.implementable.logging.Filter +import de.staropensource.engine.base.type.logging.Call /** * Handles call filtering. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/Logger.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt similarity index 93% rename from base/src/main/kotlin/de/staropensource/engine/logging/Logger.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt index d8b1ce867..c40066748 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/Logger.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt @@ -18,10 +18,11 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging +package de.staropensource.engine.base.logging -import de.staropensource.engine.logging.type.Call -import de.staropensource.engine.logging.type.Level +import de.staropensource.engine.base.EngineConfiguration +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.Level import kotlinx.datetime.Clock import kotlinx.datetime.Instant @@ -130,7 +131,7 @@ class Logger { if (Processor.check(call)) return - if (LoggerConfiguration.threadingHandler?.queue(call) == null) + if (EngineConfiguration.logThreadingHandler?.queue(call) == null) Processor.process(call) } } @@ -215,7 +216,7 @@ class Logger { /** * Flushes all log messages. * - * Tells the configured [ThreadingHandler] + * Tells the configured [LoggerThreadingHandler] * to flush all log messages to output * immediately. * @@ -225,6 +226,6 @@ class Logger { * @since v1-alpha10 */ fun flush() { - LoggerConfiguration.threadingHandler?.flush() + EngineConfiguration.logThreadingHandler?.flush() } } diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/ThreadingHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/LoggerThreadingHandler.kt similarity index 93% rename from base/src/main/kotlin/de/staropensource/engine/logging/ThreadingHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/LoggerThreadingHandler.kt index 3ab352078..6b7a28bae 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/ThreadingHandler.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/LoggerThreadingHandler.kt @@ -18,9 +18,9 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging +package de.staropensource.engine.base.logging -import de.staropensource.engine.logging.type.Call +import de.staropensource.engine.base.type.logging.Call /** * Handles multithreading. @@ -31,7 +31,7 @@ import de.staropensource.engine.logging.type.Call * * @since v1-alpha10 */ -interface ThreadingHandler { +interface LoggerThreadingHandler { // -----> Threading management /** * Starts this threading handler. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/Processor.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt similarity index 70% rename from base/src/main/kotlin/de/staropensource/engine/logging/Processor.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt index 584fa1bf9..1f20bf88c 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/Processor.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt @@ -18,16 +18,16 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging +package de.staropensource.engine.base.logging -import de.staropensource.engine.logging.implementable.Adapter -import de.staropensource.engine.logging.implementable.FormatBuilder -import de.staropensource.engine.logging.implementable.Formatter -import de.staropensource.engine.logging.implementation.SOSLSv2FormatBuilder -import de.staropensource.engine.logging.type.Call -import de.staropensource.engine.logging.type.ChannelSettings -import de.staropensource.engine.logging.type.Feature -import de.staropensource.engine.logging.type.OperationMode +import de.staropensource.engine.base.EngineConfiguration +import de.staropensource.engine.base.implementable.logging.Adapter +import de.staropensource.engine.base.implementable.logging.FormatBuilder +import de.staropensource.engine.base.implementable.logging.Formatter +import de.staropensource.engine.base.type.logging.Call +import de.staropensource.engine.base.type.logging.ChannelSettings +import de.staropensource.engine.base.type.logging.Feature +import de.staropensource.engine.base.type.logging.OperationMode import kotlin.reflect.full.primaryConstructor /** @@ -59,10 +59,10 @@ class Processor private constructor() { fun check(call: Call): Boolean { return ( // Check logger mode - LoggerConfiguration.mode == OperationMode.NOOP + EngineConfiguration.logMode == OperationMode.NOOP // Check if level is allowed - || !LoggerConfiguration.levels.contains(call.level) + || !EngineConfiguration.logLevels.contains(call.level) // Run against filters || Filterer.run(call) @@ -80,10 +80,10 @@ class Processor private constructor() { * 4. pass the finalized format to the configured [de.staropensource.engine.logging.implementable.Adapter]. * * Invoked by the configured - * [ThreadingHandler]. + * [LoggerThreadingHandler]. * * @param call [Call] metadata - * @see LoggerConfiguration.threadingHandler + * @see EngineConfiguration.logThreadingHandler * @see ChannelSettings.formatter * @see ChannelSettings.adapter * @since v1-alpha10 @@ -93,14 +93,15 @@ class Processor private constructor() { fun process(call: Call) { val format: FormatBuilder var formatFinalized: String = "" - val channelconf: ChannelSettings? = LoggerConfiguration.channelSettings[call.channel] + val channelconf: ChannelSettings? = EngineConfiguration.logChannelSettings[call.channel] var message: String = call.message // Set 'format' try { - format = (LoggerConfiguration.formatBuilder ?: SOSLSv2FormatBuilder::class).primaryConstructor!!.call(call) + format = (EngineConfiguration.logFormatBuilder).primaryConstructor!!.call(call) } catch (throwable: Throwable) { - println("Logger system failure: Configured FormatBuilder implementation '" + ((LoggerConfiguration.formatBuilder ?: SOSLSv2FormatBuilder::class).qualifiedName ?: "") + "' does not have a primary 'constructor(call: Call)'. Log messages cannot be processed.") + println("Logger system failure: Configured FormatBuilder implementation '" + ((EngineConfiguration.logFormatBuilder).qualifiedName ?: "") + "' does not have a primary 'constructor(call: Call)'. Log messages cannot be processed.") + // TODO print exception? return } @@ -109,7 +110,7 @@ class Processor private constructor() { return // Build format - for (feature: Feature in LoggerConfiguration.features) + for (feature: Feature in EngineConfiguration.logFeatures.toSet()) if (feature != Feature.FORMATTING) format.addFeature(feature) @@ -120,7 +121,7 @@ class Processor private constructor() { ) message = message.replace("<", "\\<") if ( ChannelSettings.getSetting(channelconf, "permitFormatting") as Boolean - && LoggerConfiguration.features.contains(Feature.FORMATTING) + && EngineConfiguration.logFeatures.contains(Feature.FORMATTING) ) format.addFeature(Feature.FORMATTING) // Set message @@ -132,8 +133,10 @@ class Processor private constructor() { else format.toString() - // Pass format to adapter - (ChannelSettings.getSetting(channelconf, "adapter") as Adapter).handle(call, formatFinalized) + // Pass format to adapters + @Suppress("UNCHECKED_CAST") + for (adapter: Adapter in ChannelSettings.getSetting(channelconf, "adapters") as Set) + adapter.handle(call, formatFinalized) } } } diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/type/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/package-info.kt similarity index 92% rename from base/src/main/kotlin/de/staropensource/engine/logging/type/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/package-info.kt index 865261043..263d326f4 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/type/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/package-info.kt @@ -19,8 +19,8 @@ */ /** - * Various data types. + * sos!engine's logging system. * * @since v1-alpha10 */ -package de.staropensource.engine.logging.type; +package de.staropensource.engine.base.logging diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/type/Call.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt similarity index 96% rename from base/src/main/kotlin/de/staropensource/engine/logging/type/Call.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt index 1b4632342..c662efa9f 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/type/Call.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.type +package de.staropensource.engine.base.type.logging /** * Holds information about log calls. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/type/ChannelSettings.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt similarity index 69% rename from base/src/main/kotlin/de/staropensource/engine/logging/type/ChannelSettings.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt index 73c3b620b..75a4901ae 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/type/ChannelSettings.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt @@ -1,9 +1,29 @@ -package de.staropensource.engine.logging.type +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU Affero General Public License v3 + * with an exception allowing classpath linking. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ -import de.staropensource.engine.logging.implementable.Adapter -import de.staropensource.engine.logging.implementable.Formatter -import de.staropensource.engine.logging.implementation.NoOperationFormatter -import de.staropensource.engine.logging.implementation.PrintlnAdapter +package de.staropensource.engine.base.type.logging + +import de.staropensource.engine.base.implementable.logging.Adapter +import de.staropensource.engine.base.implementable.logging.Formatter +import de.staropensource.engine.base.implementation.logging.NoOperationFormatter +import de.staropensource.engine.base.implementation.logging.adapter.PrintlnAdapter /** * Holds the configuration of one @@ -23,7 +43,7 @@ data class ChannelSettings( private val permitFormatting: Boolean? = null, private val applicationName: String? = null, private val formatter: Formatter? = null, - private val adapter: Adapter? = null, + private val adapters: Set? = null, ) { /** * Companion object of [ChannelSettings]. @@ -54,7 +74,7 @@ data class ChannelSettings( permitFormatting = null, applicationName = null, formatter = null, - adapter = null, + adapters = null, ) /** @@ -74,7 +94,7 @@ data class ChannelSettings( "permitFormatting" -> (settings?.permitFormatting ?: global.permitFormatting) != false "applicationName" -> settings?.applicationName ?: global.applicationName ?: "This application" "formatter" -> settings?.formatter ?: global.formatter ?: NoOperationFormatter.instance - "adapter" -> settings?.adapter ?: global.adapter ?: PrintlnAdapter.instance + "adapters" -> settings?.adapters ?: global.adapters ?: setOf(PrintlnAdapter.instance) else -> null } } diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/type/Feature.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt similarity index 97% rename from base/src/main/kotlin/de/staropensource/engine/logging/type/Feature.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt index b8f4ce407..c758abb2e 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/type/Feature.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.type +package de.staropensource.engine.base.type.logging /** * Represents log formatting enabledFeatures. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/type/Level.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt similarity index 97% rename from base/src/main/kotlin/de/staropensource/engine/logging/type/Level.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt index 7ba069728..a2e5ddd33 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/type/Level.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.type +package de.staropensource.engine.base.type.logging /** * Represents log call priorities. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/type/OperationMode.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt similarity index 96% rename from base/src/main/kotlin/de/staropensource/engine/logging/type/OperationMode.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt index 8f61c4b27..95e2f2495 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/type/OperationMode.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package de.staropensource.engine.logging.type +package de.staropensource.engine.base.type.logging /** * Represents how the logger functions. diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/package-info.kt similarity index 90% rename from base/src/main/kotlin/de/staropensource/engine/logging/implementable/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/package-info.kt index bcdf4ecdd..e0ec1a73e 100644 --- a/base/src/main/kotlin/de/staropensource/engine/logging/implementable/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/package-info.kt @@ -19,8 +19,8 @@ */ /** - * Interfaces and abstract classes. + * Data types used by the logging system. * * @since v1-alpha10 */ -package de.staropensource.engine.logging.implementable +package de.staropensource.engine.base.type.logging diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/LoggerConfiguration.kt b/base/src/main/kotlin/de/staropensource/engine/logging/LoggerConfiguration.kt deleted file mode 100644 index be5fe375f..000000000 --- a/base/src/main/kotlin/de/staropensource/engine/logging/LoggerConfiguration.kt +++ /dev/null @@ -1,167 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU Affero General Public License v3 - * with an exception allowing classpath linking. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.logging - -import de.staropensource.engine.logging.implementable.CrashCategory -import de.staropensource.engine.logging.implementation.SOSLSv2FormatBuilder -import de.staropensource.engine.logging.type.ChannelSettings -import de.staropensource.engine.logging.type.Feature -import de.staropensource.engine.logging.implementable.FormatBuilder -import de.staropensource.engine.logging.implementable.ShutdownHandler -import de.staropensource.engine.logging.implementation.crashcategory.InfoCrashCategory -import de.staropensource.engine.logging.type.Level -import de.staropensource.engine.logging.type.OperationMode -import kotlinx.datetime.TimeZone -import kotlin.reflect.KClass - -/** - * The configuration of this logging system. - * - * @since v1-alpha10 - */ -class LoggerConfiguration private constructor() { - /** - * Companion object of [LoggerConfiguration]. - * - * @since v1-alpha10 - */ - companion object { - // -----> Logging settings - /** - * Controls how [Logger]s should function. - * - * @since v1-alpha10 - */ - @JvmStatic - var mode: OperationMode = OperationMode.NORMAL - - /** - * Determines which levels are - * allowed to be processed. - * - * @since v1-alpha10 - */ - @JvmStatic - var levels: MutableSet = mutableSetOf( - Level.INFORMATIONAL, - Level.WARNING, - Level.ERROR, - Level.CRASH - ) - - /** - * Determines which log enabledFeatures shall - * be displayed in the final output. - * - * @since v1-alpha10 - */ - @JvmStatic - var features: MutableSet = mutableSetOf( - Feature.FORMATTING, - Feature.TIME, - Feature.LEVEL, - Feature.ORIGIN, - Feature.LINE_NUMBER, - ) - - /** - * Controls how fast the logging thread - * shall wait until processing the log - * queue after it has been processed - * minus the processing time. - * - * This only takes effect if an - * appropriate [ThreadingHandler] - * is configured. - * - * @since v1-alpha10 - */ - @JvmStatic - var threadPollingDelay: Int = 5 - - /** - * Contains log channel settings. - * - * @since v1-alpha10 - */ - @JvmStatic - var channelSettings: MutableMap = mutableMapOf() - - /** - * Contains all registered [CrashCategory]s. - * - * @since v1-alpha10 - */ - @JvmStatic - var crashCategories: LinkedHashSet = linkedSetOf( - InfoCrashCategory.instance - ) - - /** - * Controls the [ThreadingHandler] to use. - * - * This determines how multithreading - * shall be performed. Set to `null` for - * a single-threaded logger. - * - * @see ThreadingHandler - * @since v1-alpha10 - */ - @JvmStatic - var threadingHandler: ThreadingHandler? = null - - /** - * Controls the [FormatBuilder] to use. - * - * This determines how formats are built - * and how the final log output looks like. - * Set to `null` to default to [SOSLSv2FormatBuilder]. - * - * @see FormatBuilder - * @since v1-alpha10 - */ - @JvmStatic - var formatBuilder: KClass? = null - - /** - * Controls the [ShutdownHandler] to use. - * - * This determines how the - * application is shut down - * after crashing fatally. - * - * @see ShutdownHandler - * @since v1-alpha10 - */ - @JvmStatic - var shutdownHandler: ShutdownHandler? = null - - - // -----> Feature settings - /** - * Controls which [TimeZone] to use - * for [Feature.DATE] & [Feature.TIME]. - * - * @since v1-alpha10 - */ - var featureDateTimeTZ: TimeZone = TimeZone.currentSystemDefault() - } -} diff --git a/base/src/main/kotlin/de/staropensource/engine/logging/type/FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/logging/type/FormatBuilder.kt deleted file mode 100644 index 978735ddf..000000000 --- a/base/src/main/kotlin/de/staropensource/engine/logging/type/FormatBuilder.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU Affero General Public License v3 - * with an exception allowing classpath linking. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.logging.type - diff --git a/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt b/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt index a9827e2a3..a1103792f 100644 --- a/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt +++ b/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt @@ -21,7 +21,7 @@ package de.staropensource.engine.testapp import de.staropensource.engine.base.Engine -import de.staropensource.engine.logging.Logger +import de.staropensource.engine.base.logging.Logger /** * Testing program for the StarOpenSource Engine. @@ -53,7 +53,9 @@ class Main private constructor() { logger.info("Hello World!") // Shutdown engine - Engine.shutdown() + Engine.shutdownFinal() + + logger.info("You shouldn't see this") } } }