-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added a logging model module (#21)
- Loading branch information
Showing
6 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Error.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.tnboot.logging.model | ||
|
||
/** | ||
* Represents an error. | ||
*/ | ||
interface Error { | ||
val className: String | ||
val message: String? | ||
val stack: Array<StackTraceElement> | ||
val commonFrames: Int | ||
val cause: Error? | ||
val cyclic: Boolean | ||
|
||
/** | ||
* Returns a string representation of this error. | ||
*/ | ||
val repr: String | ||
} |
24 changes: 24 additions & 0 deletions
24
projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/LogPayload.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StackTraceElement>? | ||
val thread: String? | ||
val mdc: Map<String, String?> | ||
val formattedMessage: String | ||
val message: String | ||
val arguments: Array<Any?> | ||
val error: Error? | ||
} |
22 changes: 22 additions & 0 deletions
22
projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/StackTraceElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
28 changes: 28 additions & 0 deletions
28
projects/logging/logging-model/src/main/kotlin/io/tnboot/logging/model/Theme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ include( | |
|
||
include( | ||
":projects:logging:colorful", | ||
":projects:logging:logging-model", | ||
) |