Add Call.creationTime property & staticize? Logger.flush
This commit is contained in:
parent
7dced06c58
commit
1abddc3233
5 changed files with 34 additions and 21 deletions
|
@ -367,6 +367,7 @@ class Engine private constructor() {
|
|||
state = State.SHUT_DOWN_FINAL
|
||||
|
||||
// Initiate application shutdown
|
||||
Logger.flush()
|
||||
EngineConfiguration.shutdownHandler.exit(exitcode)
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}\")"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue