You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

4 years ago
4 years ago
  1. package org.slf4j.impl
  2. import cats.effect.{ContextShift, Clock, Effect, IO, Timer}
  3. import io.odin._
  4. import io.odin.slf4j.OdinLoggerBinder
  5. import scala.concurrent.ExecutionContext
  6. import _root_.monix.execution.Scheduler
  7. //effect type should be specified inbefore
  8. //log line will be recorded right after the call with no suspension
  9. class StaticLoggerBinder extends OdinLoggerBinder[IO] {
  10. val ec: ExecutionContext = Scheduler.global
  11. implicit val timer: Timer[IO] = IO.timer(ec)
  12. implicit val clock: Clock[IO] = timer.clock
  13. implicit val cs: ContextShift[IO] = IO.contextShift(ec)
  14. implicit val F: Effect[IO] = IO.ioEffect
  15. val loggers: PartialFunction[String, Logger[IO]] = {
  16. case "some.external.package.SpecificClass" =>
  17. consoleLogger[IO](minLevel = Level.Warn) //disable noisy external logs
  18. case asyncHttpClient
  19. if asyncHttpClient.startsWith("org.asynchttpclient.netty") =>
  20. consoleLogger[IO](minLevel = Level.Warn)
  21. case _ => //if wildcard case isn't provided, default logger is no-op
  22. consoleLogger[IO]()
  23. }
  24. }
  25. object StaticLoggerBinder extends StaticLoggerBinder {
  26. var REQUESTED_API_VERSION: String = "1.7"
  27. def getSingleton: StaticLoggerBinder = this
  28. }