forked from StarOpenSource/Engine
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")
|
||||
companion object {
|
||||
// -----> 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.
|
||||
*
|
||||
|
@ -189,6 +181,53 @@ class EngineConfiguration private constructor() {
|
|||
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
|
||||
/**
|
||||
* Resets either the specified
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package de.staropensource.engine.base.type
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
|
||||
/**
|
||||
* Holds data about a method caller.
|
||||
*
|
||||
|
@ -33,4 +35,6 @@ data class Origin(
|
|||
val className: String,
|
||||
val methodName: String,
|
||||
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
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
|
||||
/**
|
||||
* Defines a data type which can have
|
||||
* three valid states: [UNSET], [TRUE]
|
||||
|
@ -63,14 +65,13 @@ enum class Tristate {
|
|||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
fun toTristate(value: Boolean): Tristate {
|
||||
fun of(value: Boolean): Tristate {
|
||||
return if (value) TRUE
|
||||
else FALSE
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified [Int]
|
||||
* into a [Tristate].
|
||||
* Converts the specified [Int] into a [Tristate].
|
||||
*
|
||||
* `0` represents [FALSE],
|
||||
* `1` represents [TRUE] and
|
||||
|
@ -82,7 +83,7 @@ enum class Tristate {
|
|||
*/
|
||||
@JvmStatic
|
||||
@Throws(IndexOutOfBoundsException::class)
|
||||
fun toTristate(value: Int): Tristate? {
|
||||
fun of(value: Int): Tristate? {
|
||||
return when (value) {
|
||||
0 -> FALSE
|
||||
1 -> TRUE
|
||||
|
@ -93,13 +94,12 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* a [Boolean].
|
||||
* Converts this [Tristate] into a [Boolean].
|
||||
*
|
||||
* If this [Tristate] is set to
|
||||
* [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
|
||||
*/
|
||||
fun toBoolean(): Boolean? {
|
||||
|
@ -111,14 +111,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* a [Byte].
|
||||
* Converts this [Tristate] into a [Byte].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [Byte] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [Byte] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toByte(): Byte {
|
||||
|
@ -130,14 +129,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* an [UByte].
|
||||
* Converts this [Tristate] into an [UByte].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [UByte] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [UByte] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toUByte(): UByte {
|
||||
|
@ -149,14 +147,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* a [Short].
|
||||
* Converts this [Tristate] into a [Short].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [Short] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [Short] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toShort(): Short {
|
||||
|
@ -168,14 +165,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* an [UShort].
|
||||
* Converts this [Tristate] into an [UShort].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [UShort] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [UShort] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toUShort(): UShort {
|
||||
|
@ -187,14 +183,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* an [Int].
|
||||
* Converts this [Tristate] into an [Int].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [Int] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [Int] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toInt(): Int {
|
||||
|
@ -206,14 +201,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* an [UInt].
|
||||
* Converts this [Tristate] into an [UInt].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [UInt] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [UInt] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toUInt(): UInt {
|
||||
|
@ -225,14 +219,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* a [Long].
|
||||
* Converts this [Tristate] into a [Long].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [Long] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [Long] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toLong(): Long {
|
||||
|
@ -244,14 +237,13 @@ enum class Tristate {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts this [Tristate] into
|
||||
* an [ULong].
|
||||
* Converts this [Tristate] into an [ULong].
|
||||
*
|
||||
* [FALSE] represents `0`,
|
||||
* [TRUE] represents `1` and
|
||||
* [UNSET] represents `2`.
|
||||
*
|
||||
* @return [ULong] representation of this [Tristate] or `null` if [UNSET]
|
||||
* @return [ULong] representation or `null` if [UNSET]
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun toULong(): ULong {
|
||||
|
@ -261,4 +253,12 @@ enum class Tristate {
|
|||
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
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
import de.staropensource.engine.base.type.Origin
|
||||
|
||||
/**
|
||||
|
@ -35,4 +36,6 @@ data class Call(
|
|||
val level: Level,
|
||||
var message: String,
|
||||
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
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
import de.staropensource.engine.base.implementable.logging.Adapter
|
||||
import de.staropensource.engine.base.implementable.logging.Formatter
|
||||
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
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
|
||||
/**
|
||||
* Represents log formatting enabledFeatures.
|
||||
*
|
||||
|
@ -80,5 +82,7 @@ enum class Feature {
|
|||
*
|
||||
* @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
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
|
||||
/**
|
||||
* Represents log call priorities.
|
||||
*
|
||||
|
@ -84,5 +86,7 @@ enum class Level {
|
|||
*
|
||||
* @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
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
|
||||
/**
|
||||
* Represents how the logger functions.
|
||||
*
|
||||
|
@ -38,5 +40,7 @@ enum class OperationMode {
|
|||
*
|
||||
* @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
|
||||
|
||||
import de.staropensource.engine.base.Engine.Companion.logger
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
import de.staropensource.engine.base.utility.Environment.OperatingSystem.*
|
||||
import kotlinx.datetime.Instant
|
||||
import oshi.PlatformEnum
|
||||
|
@ -430,7 +431,26 @@ class Environment private constructor() {
|
|||
*
|
||||
* @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