Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
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.

59 lines
2.0 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 cats.implicits._
  6. import scala.concurrent.ExecutionContext
  7. import _root_.monix.execution.Scheduler
  8. import cats.arrow.FunctionK
  9. import _root_.monix.execution.Scheduler.Implicits.global
  10. import io.odin.syntax._
  11. import scala.concurrent.duration._
  12. //effect type should be specified inbefore
  13. //log line will be recorded right after the call with no suspension
  14. class StaticLoggerBinder extends OdinLoggerBinder[IO] {
  15. val ec: ExecutionContext = Scheduler.global
  16. implicit val timer: Timer[IO] = IO.timer(ec)
  17. implicit val clock: Clock[IO] = timer.clock
  18. implicit val cs: ContextShift[IO] = IO.contextShift(ec)
  19. implicit val F: Effect[IO] = IO.ioEffect
  20. val monixToCats = new FunctionK[_root_.monix.bio.Task, IO] {
  21. def apply[A](fa: _root_.monix.bio.Task[A]): IO[A] = fa.to[IO]
  22. }
  23. val (fLogger, release) =
  24. // MainModule.DefaultFileLogger.mapK(monixToCats).allocated.unsafeRunSync()
  25. fileLogger[IO](
  26. "log2.log"
  27. ).withAsync(timeWindow = 1.seconds).allocated.unsafeRunSync()
  28. // Runtime
  29. // .getRuntime()
  30. // .addShutdownHook(new Thread {
  31. // release.unsafeRunSync()
  32. // })
  33. scala.sys.addShutdownHook(release.unsafeRunSync())
  34. val loggers: PartialFunction[String, Logger[IO]] = {
  35. case "some.external.package.SpecificClass" =>
  36. consoleLogger[IO](minLevel = Level.Warn) //disable noisy external logs
  37. case asyncHttpClient
  38. if asyncHttpClient.startsWith("org.asynchttpclient.netty") =>
  39. consoleLogger[IO](minLevel = Level.Warn)
  40. case s if s.startsWith("akka.actor") || s.startsWith("wow.doge.mygame") =>
  41. consoleLogger[IO]() |+| fLogger
  42. case _ => //if wildcard case isn't provided, default logger is no-op
  43. consoleLogger[IO]()
  44. }
  45. }
  46. object StaticLoggerBinder extends StaticLoggerBinder {
  47. var REQUESTED_API_VERSION: String = "1.7"
  48. def getSingleton: StaticLoggerBinder = this
  49. }