File tree 4 files changed +50
-0
lines changed
integration/kotlinx-coroutines-slf4j
kotlin/kotlinx/coroutines/experimental/slf4j
4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Module kotlinx-coroutines-slf4j
2
+
3
+ Integration with SLF4J [ MDC] ( https://logback.qos.ch/manual/mdc.html ) .
4
+
5
+ ## Example
6
+
7
+ Extends a given Coroutine context so that the SLF4J MDC context is passed into the coroutine.
8
+
9
+ ``` kotlin
10
+ MDC .put(" kotlin" , " rocks" ) // put a value into the MDC context
11
+
12
+ launch(MDCContext (CommonPool )) {
13
+ logger.info { " ..." } // the MDC context will contain the mapping here
14
+ }
15
+ ```
16
+
17
+ # Package kotlinx.coroutines.experimental.slf4j
18
+
19
+ Integration with SLF4J [ MDC] ( https://logback.qos.ch/manual/mdc.html ) .
Original file line number Diff line number Diff line change 1
1
dependencies {
2
2
compile ' org.slf4j:slf4j-api:1.7.25'
3
+ testCompile ' io.github.microutils:kotlin-logging:1.5.4'
3
4
testRuntime ' ch.qos.logback:logback-classic:1.2.3'
4
5
testRuntime ' ch.qos.logback:logback-core:1.2.3'
5
6
}
Original file line number Diff line number Diff line change
1
+ package kotlinx.coroutines.experimental.slf4j
2
+
3
+ import mu.KotlinLogging
4
+ import org.slf4j.MDC
5
+
6
+ fun main (args : Array <String >) {
7
+ val logger = KotlinLogging .logger {}
8
+
9
+ // You can put values in the MDC at any time. Before anything else
10
+ // we put the first name
11
+ MDC .put(" first" , " Dorothy" )
12
+
13
+ // We now put the last name
14
+ MDC .put(" last" , " Parker" )
15
+
16
+ // The most beautiful two words in the English language according
17
+ // to Dorothy Parker:
18
+ logger.info(" Check enclosed." )
19
+ logger.debug(" The most beautiful two words in English." )
20
+
21
+ MDC .put(" first" , " Richard" )
22
+ MDC .put(" last" , " Nixon" )
23
+ logger.info(" I am not a crook." )
24
+ logger.info(" Attributed to the former US president. 17 Nov 1973." )
25
+ }
Original file line number Diff line number Diff line change
1
+ <appender name =" CONSOLE" class =" ch.qos.logback.core.ConsoleAppender" >
2
+ <layout >
3
+ <Pattern >%X{first} %X{last} - %m%n</Pattern >
4
+ </layout >
5
+ </appender >
You can’t perform that action at this time.
0 commit comments