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.

36 lines
1.2 KiB

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 "org.asynchttpclient.netty.channel.DefaultChannelPool" =>
  19. consoleLogger[IO](minLevel = Level.Warn)
  20. case _ => //if wildcard case isn't provided, default logger is no-op
  21. consoleLogger[IO]()
  22. }
  23. }
  24. object StaticLoggerBinder extends StaticLoggerBinder {
  25. var REQUESTED_API_VERSION: String = "1.7"
  26. def getSingleton: StaticLoggerBinder = this
  27. }