diff --git a/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Error.kt b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Error.kt new file mode 100644 index 0000000..34d1e43 --- /dev/null +++ b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Error.kt @@ -0,0 +1,18 @@ +package io.tnboot.logging.model + +/** + * Represents an error. + */ +interface Error { + val className: String + val message: String? + val stack: Array + val commonFrames: Int + val cause: Error? + val cyclic: Boolean + + /** + * Returns a string representation of this error. + */ + val repr: String +} diff --git a/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogLevel.kt b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogLevel.kt new file mode 100644 index 0000000..d1dd853 --- /dev/null +++ b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogLevel.kt @@ -0,0 +1,24 @@ +package io.tnboot.logging.model + +/** + * Log level enum, from the most verbose to the least verbose. + * + * This class exists purely as a translation layer between + * configuration and Slf4J and Logback. + */ +enum class LogLevel { + Trace, + Debug, + Info, + Warn, + Error, + ; + + override fun toString(): String = when (this) { + Trace -> "TRACE" + Debug -> "DEBUG" + Info -> "INFO" + Warn -> "WARN" + Error -> "ERROR" + } +} diff --git a/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogPayload.kt b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogPayload.kt new file mode 100644 index 0000000..56a119a --- /dev/null +++ b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogPayload.kt @@ -0,0 +1,22 @@ +package io.tnboot.logging.model + +import java.time.Instant + +/** + * [LogPayload] is a data class that represents the payload of a log + * event. This is the data that is passed to Telenor Boot Logging + * themes when a log event is created. + */ +interface LogPayload { + val at: Instant + val level: LogLevel + val sequence: Long + val loggerName: String + val caller: Array? + val thread: String? + val mdc: Map + val formattedMessage: String + val message: String + val arguments: Array + val error: Error? +} diff --git a/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/StackTraceElement.kt b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/StackTraceElement.kt new file mode 100644 index 0000000..02ef09d --- /dev/null +++ b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/StackTraceElement.kt @@ -0,0 +1,22 @@ +package io.tnboot.logging.model + +/** + * Represents a single element in a stack trace. + */ +interface StackTraceElement { + val classLoaderName: String? + val clazz: String + val method: String + val native: Boolean + val module: String? + val version: String? + val file: String? + val line: Int? + val omitted: Boolean + val alreadyShown: Boolean + + /** + * Returns a string representation of this stack trace element. + */ + val repr: String +} diff --git a/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Theme.kt b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Theme.kt new file mode 100644 index 0000000..9cfbf55 --- /dev/null +++ b/projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Theme.kt @@ -0,0 +1,28 @@ +package io.tnboot.logging.model + +/** + * [Theme] is an interface that represents a theme for Telenor Boot + * Logging. A theme is responsible for rendering a log event into a + * string that can be written to a log file or console. + */ +interface Theme { + /** + * The name of the theme. + * + * When implementing your theme, you should return a unique name, + * as this is used to identify the theme in the configuration. This + * name should be a simple string, and should not contain any + * special characters. For example: + * + * ``` + * my-super-duper-cool-theme + * ``` + * + * While no validation is done on the name, except a uniqueness + * check, it is recommended to follow the above guidelines. + */ + fun name(): String + + /** Render a log event into a string. */ + fun render(payload: LogPayload): String +} diff --git a/settings.gradle.kts b/settings.gradle.kts index c60ef13..833c9e8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,4 +7,5 @@ include( include( ":projects:logging:colorful", + ":projects:logging:logging-model", )