Skip to content

Commit

Permalink
feat: added a logging model module (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
testersen authored Apr 1, 2024
1 parent cb86bc5 commit 07704e6
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
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
}
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"
}
}
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?
}
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
}
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
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ include(

include(
":projects:logging:colorful",
":projects:logging:logging-model",
)

0 comments on commit 07704e6

Please sign in to comment.