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.

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