This library provides ZIO fiber aware MDC logging for Log4j 2.
- Add
libraryDependencies += "com.github.mlangc" %% "zio-interop-log4j2" % versionto yourbuild.sbt - Add
-Dlog4j2.threadContextMap=com.github.mlangc.zio.interop.log4j2.FiberAwareThreadContextMapto your JVM startup parameters. If you can't, try to set thelog4j2.threadContextMapsystem property programmatically as early as you can. The property must be set before Log4j2 is initialized. - Integrate
com.github.mlangc.zio.interop.log4j2.FiberAwareThreadContextMap.assertInitializedinto your initialization code. Fiber aware MDC logging will not work properly without this call. - Use
org.slf4j.MDCas you would normally and observe that it now respects fiber boundaries. - If you start getting annoyed by wrapping interactions with
MDCin ZIO effects, take a look at slf4zio which ships anMDCconvenience wrapper for ZIO calledMDZIO.