Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added a logging model module #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
)