Add Call.creationTime property & staticize? Logger.flush
All checks were successful
PRs & Pushes / test (push) Successful in 3m10s
PRs & Pushes / build-jars (push) Successful in 4m2s
PRs & Pushes / build-apidoc (push) Successful in 4m0s

This commit is contained in:
JeremyStar™ 2024-12-29 23:47:40 +01:00
parent 7dced06c58
commit 1abddc3233
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
5 changed files with 34 additions and 21 deletions

View file

@ -367,6 +367,7 @@ class Engine private constructor() {
state = State.SHUT_DOWN_FINAL state = State.SHUT_DOWN_FINAL
// Initiate application shutdown // Initiate application shutdown
Logger.flush()
EngineConfiguration.shutdownHandler.exit(exitcode) EngineConfiguration.shutdownHandler.exit(exitcode)
} }

View file

@ -20,8 +20,8 @@
package de.staropensource.engine.base.implementation.logging.formatbuilder package de.staropensource.engine.base.implementation.logging.formatbuilder
import de.staropensource.engine.base.EngineConfiguration 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.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.Call
import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.type.logging.ChannelSettings
import de.staropensource.engine.base.type.logging.Feature import de.staropensource.engine.base.type.logging.Feature
@ -115,7 +115,7 @@ open class SOSLSv2FormatBuilder(call: Call, channelSettings: ChannelSettings?) :
else else
format.append("[") 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") format.append("${differenceTime.inWholeSeconds}.${differenceTime.inWholeMilliseconds.minus(differenceTime.inWholeSeconds.times(1000))}s")
if (enabledFeatures.contains(Feature.FORMATTING)) if (enabledFeatures.contains(Feature.FORMATTING))

View file

@ -21,7 +21,7 @@ package de.staropensource.engine.base.logging
import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.EngineConfiguration
import de.staropensource.engine.base.annotation.NonKotlinContact 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.implementable.stream.Stream
import de.staropensource.engine.base.implementation.stream.FileAccessStream import de.staropensource.engine.base.implementation.stream.FileAccessStream
import de.staropensource.engine.base.implementation.stream.LoggerStream import de.staropensource.engine.base.implementation.stream.LoggerStream
@ -70,6 +70,23 @@ class Logger {
@JvmStatic @JvmStatic
@Suppress("Unused") @Suppress("Unused")
val instance = Logger() 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 // -----> 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 * Returns a [Stream] for
* writing to the specified * writing to the specified

View file

@ -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.Adapter
import de.staropensource.engine.base.implementable.logging.FormatBuilder import de.staropensource.engine.base.implementable.logging.FormatBuilder
import de.staropensource.engine.base.implementable.formatter.Formatter 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.Call
import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.type.logging.ChannelSettings
import de.staropensource.engine.base.type.logging.Feature 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]. * 4. pass the finalized format to the configured [Adapter].
* *
* Invoked by the configured * Invoked by the configured
* [LoggerThreadingHandler]. * [ThreadingHandler].
* *
* @param call [Call] metadata * @param call [Call] metadata
* @see EngineConfiguration.logThreadingHandler * @see EngineConfiguration.logThreadingHandler

View file

@ -21,6 +21,8 @@ package de.staropensource.engine.base.type.logging
import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.EngineConfiguration
import de.staropensource.engine.base.type.Origin import de.staropensource.engine.base.type.Origin
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
/** /**
* Holds information about log calls. * Holds information about log calls.
@ -38,5 +40,14 @@ data class Call(
var message: String, var message: String,
val channel: String = "default", 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}\")" 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}\")"
} }