rocketraman opened a new issue, #71:
URL: https://github.com/apache/logging-log4j-kotlin/issues/71
Using log4j2 context kind of sucks. The assumption that context will always
be set at the Thread or coroutine level is IMO false, and sometimes we just
want to set context for a particular block of code, or for a particular logger.
We should have a way to do something like this outside of a coroutine /
suspending context:
```kotlin
withContextMap(...) {
// log something
}
```
Possible implementations (only map shown here, but similar for stack)?
```kotlin
fun <T> withContextMap(
map: Map<String, String>,
block: () -> T,
): T {
val oldMap = ContextMap.view
return try {
ContextMap += map
block()
} finally {
ContextMap.clear()
ContextMap += oldMap
}
}
```
Could also be related to
https://github.com/apache/logging-log4j-kotlin/issues/36. We may want to do
something like:
```kotlin
val log = parentLog.withContext(...)
...
log.debug { ... }
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]