Add 'fullTypePath' setting, give data types some love
This commit is contained in:
parent
60ce99305b
commit
d0dbdbeef8
9 changed files with 126 additions and 45 deletions
|
@ -50,14 +50,6 @@ class EngineConfiguration private constructor() {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
companion object {
|
companion object {
|
||||||
// -----> Core engine
|
// -----> Core engine
|
||||||
/**
|
|
||||||
* Controls which [TimeZone] to use
|
|
||||||
* for date and time synchronization.
|
|
||||||
*
|
|
||||||
* @since v1-alpha10
|
|
||||||
*/
|
|
||||||
var timezone: TimeZone = TimeZone.UTC
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls how the engine should shut down.
|
* Controls how the engine should shut down.
|
||||||
*
|
*
|
||||||
|
@ -189,6 +181,53 @@ class EngineConfiguration private constructor() {
|
||||||
var logFormatBuilder: KClass<FormatBuilder> = SOSLSv2FormatBuilder::class as KClass<FormatBuilder>
|
var logFormatBuilder: KClass<FormatBuilder> = SOSLSv2FormatBuilder::class as KClass<FormatBuilder>
|
||||||
|
|
||||||
|
|
||||||
|
// -----> Miscellaneous
|
||||||
|
/**
|
||||||
|
* Controls which [TimeZone] to use
|
||||||
|
* for date and time synchronization.
|
||||||
|
*
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
var timezone: TimeZone = TimeZone.UTC
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls whether the package
|
||||||
|
* of the data type class shall
|
||||||
|
* be prepended by the
|
||||||
|
* [toString] method of data types.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* ```kotlin
|
||||||
|
* EngineConfiguration.fullTypePath = false
|
||||||
|
* println(Origin(
|
||||||
|
* packageName = "some.package",
|
||||||
|
* className = "SomeClass",
|
||||||
|
* methodName = "someMethod",
|
||||||
|
* lineNumber = 24u,
|
||||||
|
* ))
|
||||||
|
*
|
||||||
|
* println("----")
|
||||||
|
*
|
||||||
|
* EngineConfiguration.fullTypePath = true
|
||||||
|
* println(Origin(
|
||||||
|
* packageName = "some.package",
|
||||||
|
* className = "SomeClass",
|
||||||
|
* methodName = "someMethod",
|
||||||
|
* lineNumber = 24u,
|
||||||
|
* ))
|
||||||
|
* ```
|
||||||
|
* Output:
|
||||||
|
* ```plain
|
||||||
|
* Origin(packageName = "some.package", className = "SomeClass", methodName = "someMethod", lineNumber = 24u)
|
||||||
|
* ----
|
||||||
|
* de.staropensource.engine.base.type.Origin(packageName = "some.package", className = "SomeClass", methodName = "someMethod", lineNumber = 24u)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
var fullTypePath: Boolean = false
|
||||||
|
|
||||||
|
|
||||||
// -----> Management methods
|
// -----> Management methods
|
||||||
/**
|
/**
|
||||||
* Resets either the specified
|
* Resets either the specified
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.type
|
package de.staropensource.engine.base.type
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds data about a method caller.
|
* Holds data about a method caller.
|
||||||
*
|
*
|
||||||
|
@ -33,4 +35,6 @@ data class Origin(
|
||||||
val className: String,
|
val className: String,
|
||||||
val methodName: String,
|
val methodName: String,
|
||||||
val lineNumber: UInt,
|
val lineNumber: UInt,
|
||||||
)
|
) {
|
||||||
|
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type." else ""}Origin(packageName = \"${packageName}\", className = \"${className}\", methodName = \"${methodName}\", lineNumber = \"${lineNumber}\")"
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.type
|
package de.staropensource.engine.base.type
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a data type which can have
|
* Defines a data type which can have
|
||||||
* three valid states: [UNSET], [TRUE]
|
* three valid states: [UNSET], [TRUE]
|
||||||
|
@ -63,14 +65,13 @@ enum class Tristate {
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun toTristate(value: Boolean): Tristate {
|
fun of(value: Boolean): Tristate {
|
||||||
return if (value) TRUE
|
return if (value) TRUE
|
||||||
else FALSE
|
else FALSE
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the specified [Int]
|
* Converts the specified [Int] into a [Tristate].
|
||||||
* into a [Tristate].
|
|
||||||
*
|
*
|
||||||
* `0` represents [FALSE],
|
* `0` represents [FALSE],
|
||||||
* `1` represents [TRUE] and
|
* `1` represents [TRUE] and
|
||||||
|
@ -82,7 +83,7 @@ enum class Tristate {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Throws(IndexOutOfBoundsException::class)
|
@Throws(IndexOutOfBoundsException::class)
|
||||||
fun toTristate(value: Int): Tristate? {
|
fun of(value: Int): Tristate? {
|
||||||
return when (value) {
|
return when (value) {
|
||||||
0 -> FALSE
|
0 -> FALSE
|
||||||
1 -> TRUE
|
1 -> TRUE
|
||||||
|
@ -93,13 +94,12 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into a [Boolean].
|
||||||
* a [Boolean].
|
|
||||||
*
|
*
|
||||||
* If this [Tristate] is set to
|
* If this [Tristate] is set to
|
||||||
* [UNSET], `null` will be returned.
|
* [UNSET], `null` will be returned.
|
||||||
*
|
*
|
||||||
* @return [Boolean] representation of this [Tristate] or `null` if [UNSET]
|
* @return [Boolean] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toBoolean(): Boolean? {
|
fun toBoolean(): Boolean? {
|
||||||
|
@ -111,14 +111,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into a [Byte].
|
||||||
* a [Byte].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [Byte] representation of this [Tristate] or `null` if [UNSET]
|
* @return [Byte] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toByte(): Byte {
|
fun toByte(): Byte {
|
||||||
|
@ -130,14 +129,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into an [UByte].
|
||||||
* an [UByte].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [UByte] representation of this [Tristate] or `null` if [UNSET]
|
* @return [UByte] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toUByte(): UByte {
|
fun toUByte(): UByte {
|
||||||
|
@ -149,14 +147,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into a [Short].
|
||||||
* a [Short].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [Short] representation of this [Tristate] or `null` if [UNSET]
|
* @return [Short] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toShort(): Short {
|
fun toShort(): Short {
|
||||||
|
@ -168,14 +165,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into an [UShort].
|
||||||
* an [UShort].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [UShort] representation of this [Tristate] or `null` if [UNSET]
|
* @return [UShort] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toUShort(): UShort {
|
fun toUShort(): UShort {
|
||||||
|
@ -187,14 +183,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into an [Int].
|
||||||
* an [Int].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [Int] representation of this [Tristate] or `null` if [UNSET]
|
* @return [Int] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toInt(): Int {
|
fun toInt(): Int {
|
||||||
|
@ -206,14 +201,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into an [UInt].
|
||||||
* an [UInt].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [UInt] representation of this [Tristate] or `null` if [UNSET]
|
* @return [UInt] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toUInt(): UInt {
|
fun toUInt(): UInt {
|
||||||
|
@ -225,14 +219,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into a [Long].
|
||||||
* a [Long].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [Long] representation of this [Tristate] or `null` if [UNSET]
|
* @return [Long] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toLong(): Long {
|
fun toLong(): Long {
|
||||||
|
@ -244,14 +237,13 @@ enum class Tristate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this [Tristate] into
|
* Converts this [Tristate] into an [ULong].
|
||||||
* an [ULong].
|
|
||||||
*
|
*
|
||||||
* [FALSE] represents `0`,
|
* [FALSE] represents `0`,
|
||||||
* [TRUE] represents `1` and
|
* [TRUE] represents `1` and
|
||||||
* [UNSET] represents `2`.
|
* [UNSET] represents `2`.
|
||||||
*
|
*
|
||||||
* @return [ULong] representation of this [Tristate] or `null` if [UNSET]
|
* @return [ULong] representation or `null` if [UNSET]
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun toULong(): ULong {
|
fun toULong(): ULong {
|
||||||
|
@ -261,4 +253,12 @@ enum class Tristate {
|
||||||
UNSET -> 2UL
|
UNSET -> 2UL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts this [Tristate] into a [String].
|
||||||
|
*
|
||||||
|
* @return string representation
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type." else ""}Tristate.${name}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.type.logging
|
package de.staropensource.engine.base.type.logging
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
import de.staropensource.engine.base.type.Origin
|
import de.staropensource.engine.base.type.Origin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,4 +36,6 @@ data class Call(
|
||||||
val level: Level,
|
val level: Level,
|
||||||
var message: String,
|
var message: String,
|
||||||
val channel: String = "default",
|
val channel: String = "default",
|
||||||
)
|
) {
|
||||||
|
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}\")"
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.type.logging
|
package de.staropensource.engine.base.type.logging
|
||||||
|
|
||||||
|
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.Formatter
|
import de.staropensource.engine.base.implementable.logging.Formatter
|
||||||
import de.staropensource.engine.base.implementation.logging.NoOperationFormatter
|
import de.staropensource.engine.base.implementation.logging.NoOperationFormatter
|
||||||
|
@ -98,4 +99,6 @@ data class ChannelSettings(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}ChannelSettings(enable = ${enable}, sanitizeMessage = ${sanitizeMessage}, permitFormatting = ${permitFormatting}, applicationName = ${applicationName}, formatter = ${formatter}, adapters = ${adapters?.toList()}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.type.logging
|
package de.staropensource.engine.base.type.logging
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents log formatting enabledFeatures.
|
* Represents log formatting enabledFeatures.
|
||||||
*
|
*
|
||||||
|
@ -80,5 +82,7 @@ enum class Feature {
|
||||||
*
|
*
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
LINE_NUMBER
|
LINE_NUMBER;
|
||||||
|
|
||||||
|
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}Feature.${name}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.type.logging
|
package de.staropensource.engine.base.type.logging
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents log call priorities.
|
* Represents log call priorities.
|
||||||
*
|
*
|
||||||
|
@ -84,5 +86,7 @@ enum class Level {
|
||||||
*
|
*
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
CRASH
|
CRASH;
|
||||||
|
|
||||||
|
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}Level.${name}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.type.logging
|
package de.staropensource.engine.base.type.logging
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents how the logger functions.
|
* Represents how the logger functions.
|
||||||
*
|
*
|
||||||
|
@ -38,5 +40,7 @@ enum class OperationMode {
|
||||||
*
|
*
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
NORMAL,
|
NORMAL;
|
||||||
|
|
||||||
|
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.type.logging." else ""}OperationMode.${name}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package de.staropensource.engine.base.utility
|
package de.staropensource.engine.base.utility
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine.Companion.logger
|
import de.staropensource.engine.base.Engine.Companion.logger
|
||||||
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
import de.staropensource.engine.base.utility.Environment.OperatingSystem.*
|
import de.staropensource.engine.base.utility.Environment.OperatingSystem.*
|
||||||
import kotlinx.datetime.Instant
|
import kotlinx.datetime.Instant
|
||||||
import oshi.PlatformEnum
|
import oshi.PlatformEnum
|
||||||
|
@ -430,7 +431,26 @@ class Environment private constructor() {
|
||||||
*
|
*
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
MACOS,
|
MACOS;
|
||||||
|
|
||||||
|
override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.utility." else ""}Environment\$OperatingSystem.${name}"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the human-friendly name
|
||||||
|
* of this operating system.
|
||||||
|
*
|
||||||
|
* @return human-friendly name
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
fun humanFriendly(): String = when (this) {
|
||||||
|
LINUX -> "Linux"
|
||||||
|
FREEBSD -> "FreeBSD"
|
||||||
|
NETBSD -> "NetBSD"
|
||||||
|
OPENBSD -> "OpenBSD"
|
||||||
|
ANDROID -> "Android"
|
||||||
|
WINDOWS -> "Windows"
|
||||||
|
MACOS -> "macOS"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue