Monix

Module slog4s-monix provides basic integration with monix effect system. It leverages TaskLocal for context propagation.

slf4j example

This example demonstrates how to make an slf4j specific instance of LoggingContext and LoggerFactory backed by monix’s TaskLocal.

import monix.eval._
import slog4s._
import slog4s.shared._
import slog4s.monix._
import slog4s.slf4j._

Slf4jFactory[Task].makeFromBuilder(MonixContextRuntimeBuilder)
// res0: Task[LoggingRuntime[Task]] = Map(
//   Map(
//     ContextSwitch(
//       Eval(monix.eval.TaskLocal$$$Lambda$8061/0x00000008025f7b10@5bd13960),
//       monix.eval.TaskLocal$$$Lambda$8060/0x00000008025f7558@2c63d803,
//       null
//     ),
//     slog4s.monix.MonixContextRuntime$$$Lambda$8062/0x00000008025f2000@5a6749a4,
//     StackTrace(
//       List(
//         monix.eval.internal.TaskTracing$.buildFrame(TaskTracing.scala:52),
//         monix.eval.internal.TaskTracing$.buildCachedFrame(TaskTracing.scala:43),
//         monix.eval.internal.TaskTracing$.cached(TaskTracing.scala:38),
//         monix.eval.Task.map(Task.scala:2027),
//         slog4s.monix.MonixContextRuntime$.make(MonixContextRuntime.scala:17),
//         slog4s.monix.MonixContextRuntimeBuilder$.make(MonixContextRuntimeBuilder.scala:9),
//         slog4s.monix.MonixContextRuntimeBuilder$.make(MonixContextRuntimeBuilder.scala:6),
//         slog4s.slf4j.Slf4jFactory$Slf4jFactoryBuilder.makeFromBuilder(Slf4jFactory.scala:52),
//         repl.MdocSession$MdocApp.<init>(monix.md:23),
//         repl.MdocSession$.app(monix.md:3),
//         mdoc.internal.document.DocumentBuilder$$doc$.$anonfun$build$2(DocumentBuilder.scala:89),
//         scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23),
//         scala.util.DynamicVariable.withValue(DynamicVariable.scala:62),
//         scala.Console$.withErr(Console.scala:196),
//         mdoc.internal.document.DocumentBuilder$$doc$.$anonfun$build$1(DocumentBuilder.scala:89),
//         scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23),
//         scala.util.DynamicVariable.withValue(DynamicVariable.scala:62),
//         scala.Console$.withOut(Console.scala:167),
//         mdoc.internal.document.DocumentBuilder$$doc$.build(DocumentBuilder.scala:88),
//         mdoc.internal.markdown.MarkdownBuilder$.$anonfun$buildDocument$2(MarkdownBuilder.scala:47),
//         mdoc.internal.markdown.MarkdownBuilder$$anon$1.run(MarkdownBuilder.scala:104)
//       )
//     )
//   ),
//   slog4s.slf4j.Slf4jFactory$Slf4jFactoryBuilder$$Lambda$8063/0x00000008025f2cc0@268fa0ce,
//   StackTrace(
//     List(
//       monix.eval.internal.TaskTracing$.buildFrame(TaskTracing.scala:52),
//       monix.eval.internal.TaskTracing$.buildCachedFrame(TaskTracing.scala:43),
//       monix.eval.internal.TaskTracing$.cached(TaskTracing.scala:38),
// ...