From 1abddc3233eed6e77d203e7a74b53d28adad98e5 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 29 Dec 2024 23:47:40 +0100 Subject: [PATCH] Add Call.creationTime property & staticize? Logger.flush --- .../de/staropensource/engine/base/Engine.kt | 1 + .../formatbuilder/SOSLSv2FormatBuilder.kt | 4 +-- .../engine/base/logging/Logger.kt | 35 ++++++++++--------- .../engine/base/logging/Processor.kt | 4 +-- .../engine/base/type/logging/Call.kt | 11 ++++++ 5 files changed, 34 insertions(+), 21 deletions(-) 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 d48601a..301b7c1 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt @@ -367,6 +367,7 @@ class Engine private constructor() { state = State.SHUT_DOWN_FINAL // Initiate application shutdown + Logger.flush() EngineConfiguration.shutdownHandler.exit(exitcode) } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt index 0ee5768..0d18498 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt @@ -20,8 +20,8 @@ package de.staropensource.engine.base.implementation.logging.formatbuilder 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.logging.Logger import de.staropensource.engine.base.type.logging.Call import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.type.logging.Feature @@ -115,7 +115,7 @@ open class SOSLSv2FormatBuilder(call: Call, channelSettings: ChannelSettings?) : else format.append("[") - val differenceTime: Duration = Clock.System.now().minus(Logger.Companion.initializationTime) + val differenceTime: Duration = call.creationTime.minus(Logger.Companion.initializationTime) format.append("${differenceTime.inWholeSeconds}.${differenceTime.inWholeMilliseconds.minus(differenceTime.inWholeSeconds.times(1000))}s") if (enabledFeatures.contains(Feature.FORMATTING)) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt index 29e5369..cc9323c 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt @@ -21,7 +21,7 @@ package de.staropensource.engine.base.logging import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.annotation.NonKotlinContact -import de.staropensource.engine.base.implementable.logging.LoggerThreadingHandler +import de.staropensource.engine.base.implementable.logging.ThreadingHandler import de.staropensource.engine.base.implementable.stream.Stream import de.staropensource.engine.base.implementation.stream.FileAccessStream import de.staropensource.engine.base.implementation.stream.LoggerStream @@ -70,6 +70,23 @@ class Logger { @JvmStatic @Suppress("Unused") val instance = Logger() + + + /** + * Flushes all log messages. + * + * Tells the configured [ThreadingHandler] + * to flush all log messages to output + * immediately. + * + * This method is blocking, until all + * log messages have been processed + * + * @since v1-alpha10 + */ + fun flush() { + EngineConfiguration.logThreadingHandler?.flush() + } } @@ -217,22 +234,6 @@ class Logger { // -----> Utility - /** - * Flushes all log messages. - * - * Tells the configured [LoggerThreadingHandler] - * to flush all log messages to output - * immediately. - * - * This method is blocking, until all - * log messages have been processed - * - * @since v1-alpha10 - */ - fun flush() { - EngineConfiguration.logThreadingHandler?.flush() - } - /** * Returns a [Stream] for * writing to the specified diff --git a/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt index 75045c8..2f9f0e2 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt @@ -23,7 +23,7 @@ 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.formatter.Formatter -import de.staropensource.engine.base.implementable.logging.LoggerThreadingHandler +import de.staropensource.engine.base.implementable.logging.ThreadingHandler import de.staropensource.engine.base.type.logging.Call import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.type.logging.Feature @@ -82,7 +82,7 @@ class Processor private constructor() { * 4. pass the finalized format to the configured [Adapter]. * * Invoked by the configured - * [LoggerThreadingHandler]. + * [ThreadingHandler]. * * @param call [Call] metadata * @see EngineConfiguration.logThreadingHandler diff --git a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt index a31209d..a63714c 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt @@ -21,6 +21,8 @@ package de.staropensource.engine.base.type.logging import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.type.Origin +import kotlinx.datetime.Clock +import kotlinx.datetime.Instant /** * Holds information about log calls. @@ -38,5 +40,14 @@ data class Call( var message: String, val channel: String = "default", ) { + /** + * Contains the time at which + * this instance was created. + * + * @since v1-alpha10 + */ + val creationTime: Instant = Clock.System.now() + + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}Call(origin = ${origin}, level = Level.${level.name}, message = \"${message}\", channel = \"${channel}\")" }