https://github.com/mlangc/zio-interop-log4j2
ZIO Fiber aware MDC logging for LOG4J2
https://github.com/mlangc/zio-interop-log4j2
log4j2 scala zio
Last synced: 3 days ago
JSON representation
ZIO Fiber aware MDC logging for LOG4J2
- Host: GitHub
- URL: https://github.com/mlangc/zio-interop-log4j2
- Owner: mlangc
- License: apache-2.0
- Created: 2019-09-14T08:17:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-02T21:44:39.000Z (over 3 years ago)
- Last Synced: 2024-08-03T01:17:21.288Z (9 months ago)
- Topics: log4j2, scala, zio
- Language: Scala
- Size: 34.2 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
- awesome-zio - zio-interop-log4j2
README
# ZIO Interop Log4J2
[](https://oss.sonatype.org/content/repositories/releases/com/github/mlangc/zio-interop-log4j2_2.13)
[](https://oss.sonatype.org/content/repositories/snapshots/com/github/mlangc/zio-interop-log4j2_2.13/)This library provides ZIO fiber aware MDC logging for Log4j 2.
## Usage
1. Add `libraryDependencies += "com.github.mlangc" %% "zio-interop-log4j2" % version` to your `build.sbt`
1. Add `-Dlog4j2.threadContextMap=com.github.mlangc.zio.interop.log4j2.FiberAwareThreadContextMap` to your JVM startup parameters. If you can't,
try to set the `log4j2.threadContextMap` system property programmatically as early as you can. The property must be set before Log4j2 is
initialized.
1. Integrate `com.github.mlangc.zio.interop.log4j2.FiberAwareThreadContextMap.assertInitialized` into your initialization code. Fiber aware MDC
logging will not work properly without this call.
1. Use `org.slf4j.MDC` as you would normally and observe that it now respects fiber boundaries.
1. If you start getting annoyed by wrapping interactions with `MDC` in ZIO effects, take a look at [slf4zio](https://github.com/mlangc/slf4zio)
which ships an `MDC` convenience wrapper for ZIO called `MDZIO`.