Tower Guidev2
07/14/2022, 1:04 PMJakub Gwóźdź
09/02/2022, 6:58 AMJohn Kasper Svergja
10/17/2022, 11:17 AMwithLoggingContext
). Is there considered any best practices for MDC and exceptions?
The current implementation of withLoggingContext clears all MDC fields if an exception inside the flow occurs. I would very much like the exception to contain the MDC-information.
One solution could be that withLoggingContext
provides an option to provided an exception handler. (I think it is important not to couple the exception handling to close to the framework).
Do you have any thoughts about this/what do you think? Or any suggestion on how the mdc is kept for exceptions?
For my case I think the best use of an exception handler would be to add an āmetaā-exception to the original exception (addSuppressed
method ) (which is what I have done in my code, by creating a wrapper method around withLoggingContext
)Endre Deak
11/16/2022, 9:44 PMimport kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import org.junit.jupiter.api.Test
internal class MdcTest {
@Test
fun testMdcContextBehavior() = runBlocking {
withContext(MDCContext(mapOf("foo" to "bar"))) {
logger.warn { "context should have bar" }
assertEquals(MDC.get("foo"}), "bar")
awaitAll(
async { assertMdcContext("bar1") },
async { assertMdcContext("bar2") }
)
logger.warn { "context should have bar " }
assertEquals(MDC.get("foo"), "bar")
}
}
private suspend fun assertMdcContext(id: String) {
withContext(MDCContext(mapOf("foo" to id))) {
logger.warn { "message with $id" }
assertEquals(MDC.get("foo"), id)
}
}
}
oshai
12/18/2022, 2:33 PMDjuro
05/26/2023, 8:08 PMoshai
05/29/2023, 6:12 PMoshai
06/17/2023, 9:18 AMio.github.oshai:kotlin-logging-jvm:4.0.0-beta-29
benkuly
06/29/2023, 3:08 PMcom.github.tony19:logback-android
with version 4?oshai
07/13/2023, 7:48 AMģ¤ėķ
07/25/2023, 1:28 PMjavaru
08/02/2023, 8:11 PMKLogger
into some methods requiring a SLF4J Logger
. In 5.x, Klogger
no longer extends org.slf4j.Logger
And so we canāt directly pass it in. In this comment for Issue 264, it was said:
The idea is that slf4j will still be supported, but instead of inheritance it will be via wrapping it.Iām not seeing how to wrap a
KLogger
in order to make it useable as a SLF4J Logger
. Any guidance?Victor Harlan Lacson
08/04/2023, 7:49 AMholgerbrandl
08/09/2023, 9:19 AMinternal
to allow visibility from other source modules in the same gradle project? E.g. I want to use some internal
method defined in the main module from within the test module.pambrose
08/23/2023, 6:50 PMcompanion object : KLogging()
It appears that with 5.0, one has to explicitly create a logger value with val logger = KotlinLogging.logger {}
. Is that correct?oshai
08/27/2023, 3:30 PMAsaf Peleg
10/03/2023, 1:07 AMMitul
10/31/2023, 12:49 PMMitul
10/31/2023, 12:49 PMPhil Richardson
11/22/2023, 10:25 AMMark
12/21/2023, 8:40 AMLocationAwareKLogger
actually grab the class name from which the log call is made? I canāt seem to find the relevant code.
For context of why Iām asking: https://kotlinlang.slack.com/archives/CTJB58X7X/p1703144409394349Klitos Kyriacou
01/09/2024, 3:40 PMMikolaj
02/22/2024, 10:15 AMAtul Gupta
08/18/2024, 5:47 PMkotlin-logger
vs Napier?Gilles Barbier
08/21/2024, 10:09 PMnull
? I do not want to do expr?.<http://logger.info|logger.info> { it }
to avoid calculating the expr whatever the logging level.Sabeeh
10/17/2024, 8:41 AMChris Lee
10/31/2024, 12:15 AMlaunch(MDCcontext())
all over the place or things break.Nikky
10/31/2024, 5:28 AMDmytro Koval
11/06/2024, 11:58 AMSlackbot
01/16/2025, 6:37 PM