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.

88 lines
2.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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 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. import scala.collection.immutable.ArraySeq
  13. import io.odin.json.Formatter
  14. //effect type should be specified inbefore
  15. //log line will be recorded right after the call with no suspension
  16. class StaticLoggerBinder extends OdinLoggerBinder[IO] {
  17. val ec: ExecutionContext = Scheduler.global
  18. implicit val timer: Timer[IO] = IO.timer(ec)
  19. implicit val clock: Clock[IO] = timer.clock
  20. implicit val cs: ContextShift[IO] = IO.contextShift(ec)
  21. implicit val F: Effect[IO] = IO.ioEffect
  22. val monixToCats = new FunctionK[_root_.monix.bio.Task, IO] {
  23. def apply[A](fa: _root_.monix.bio.Task[A]): IO[A] = fa.to[IO]
  24. }
  25. private lazy val (defaultConsoleLogger, release1) =
  26. consoleLogger[IO](minLevel = Level.Debug)
  27. .withAsync(timeWindow = 1.milliseconds)
  28. .allocated
  29. .unsafeRunSync()
  30. private lazy val (mainFileLogger, release2) =
  31. fileLogger[IO](
  32. "application-log-2.log",
  33. Formatter.json,
  34. minLevel = Level.Debug
  35. ).withAsync(timeWindow = 1.milliseconds)
  36. .allocated
  37. .unsafeRunSync()
  38. private lazy val (eventBusFileLogger, release3) =
  39. fileLogger[IO](
  40. "eventbus.log",
  41. Formatter.json,
  42. minLevel = Level.Debug
  43. ).withAsync(timeWindow = 1.milliseconds)
  44. .allocated
  45. .unsafeRunSync()
  46. {
  47. ArraySeq(release1, release2, release3).foreach(r =>
  48. sys.addShutdownHook(r.unsafeRunSync())
  49. )
  50. }
  51. val loggers: PartialFunction[String, Logger[IO]] = {
  52. case "some.external.package.SpecificClass" =>
  53. //disable noisy external logs
  54. defaultConsoleLogger.withMinimalLevel(Level.Warn)
  55. case asyncHttpClient
  56. if asyncHttpClient.startsWith("org.asynchttpclient.netty") =>
  57. defaultConsoleLogger.withMinimalLevel(Level.Warn)
  58. // case s
  59. // if s.startsWith(
  60. // "wow.doge.mygame.subsystems.movement.PlayerMovementEventHandler"
  61. // ) =>
  62. // defaultConsoleLogger.withMinimalLevel( Level.Trace) //selectively turn on trace logging for specific classes
  63. case s if s.startsWith("wow.doge.mygame.events.EventBus") =>
  64. defaultConsoleLogger.withMinimalLevel(Level.Debug) |+| eventBusFileLogger
  65. case s if s.startsWith("akka.actor") || s.startsWith("wow.doge.mygame") =>
  66. defaultConsoleLogger.withMinimalLevel(Level.Debug) |+| mainFileLogger
  67. case _ => //if wildcard case isn't provided, default logger is no-op
  68. defaultConsoleLogger.withMinimalLevel(Level.Debug)
  69. }
  70. }
  71. object StaticLoggerBinder extends StaticLoggerBinder {
  72. var REQUESTED_API_VERSION: String = "1.7"
  73. def getSingleton: StaticLoggerBinder = this
  74. }