Skip to content

Commit

Permalink
1.1: add creation instant to slf4j marker
Browse files Browse the repository at this point in the history
  • Loading branch information
frost13it committed Dec 29, 2021
1 parent 1a9fdb7 commit c79839e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'jacoco'
id 'org.jetbrains.kotlin.jvm' version '1.4.32'
id 'ru.kontur.kinfra.presets' version '1.5'
id 'me.champeau.gradle.jmh' version '0.5.3'
id 'me.champeau.jmh' version '0.6.6'
}

ext {
Expand All @@ -23,7 +23,7 @@ ext {
}

group = "ru.kontur.kinfra"
version = "1.0"
version = "1.1"

dependencies {
implementation libs.slf4jApi
Expand Down Expand Up @@ -71,7 +71,7 @@ publishing {
}

jmh {
include = ["benchmarks.SimpleLogging.*"]
includes = ["benchmarks.*"]
benchmarkMode = ["avgt"]
batchSize = 100_000
iterations = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ru.kontur.kinfra.logging.backend.slf4j
import org.slf4j.Marker
import org.slf4j.MarkerFactory
import ru.kontur.kinfra.logging.backend.LoggingRequest
import java.time.Instant

/**
* Marker that allows an SLF4J implementation to access [LoggingRequest].
Expand All @@ -14,6 +15,13 @@ public class LoggingRequestMarker private constructor(
private val delegate: Marker
) : Marker by delegate {

/**
* Time of creation of this marker.
*
* Provides higher resolution than `LoggingEvent.getTimeStamp()` from Logback 1.2.
*/
public val createdAt: Instant = Instant.now()

public constructor(request: LoggingRequest) : this(request, MarkerFactory.getDetachedMarker(NAME))

// Serialize a plain marker without non-serializable LoggingRequest
Expand Down

0 comments on commit c79839e

Please sign in to comment.