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.
|
|
package org.slf4j.impl
import cats.effect.{ContextShift, Clock, Effect, IO, Timer} import io.odin._ import io.odin.slf4j.OdinLoggerBinder import cats.implicits._
import scala.concurrent.ExecutionContext import _root_.monix.execution.Scheduler import cats.arrow.FunctionK import _root_.monix.execution.Scheduler.Implicits.global import io.odin.syntax._ import scala.concurrent.duration._
//effect type should be specified inbefore
//log line will be recorded right after the call with no suspension
class StaticLoggerBinder extends OdinLoggerBinder[IO] {
val ec: ExecutionContext = Scheduler.global implicit val timer: Timer[IO] = IO.timer(ec) implicit val clock: Clock[IO] = timer.clock implicit val cs: ContextShift[IO] = IO.contextShift(ec) implicit val F: Effect[IO] = IO.ioEffect
val monixToCats = new FunctionK[_root_.monix.bio.Task, IO] { def apply[A](fa: _root_.monix.bio.Task[A]): IO[A] = fa.to[IO] }
val (fLogger, release) = // MainModule.DefaultFileLogger.mapK(monixToCats).allocated.unsafeRunSync()
fileLogger[IO]( "log2.log" ).withAsync(timeWindow = 1.seconds).allocated.unsafeRunSync() // Runtime
// .getRuntime()
// .addShutdownHook(new Thread {
// release.unsafeRunSync()
// })
scala.sys.addShutdownHook(release.unsafeRunSync()) val loggers: PartialFunction[String, Logger[IO]] = { case "some.external.package.SpecificClass" => consoleLogger[IO](minLevel = Level.Warn) //disable noisy external logs
case asyncHttpClient if asyncHttpClient.startsWith("org.asynchttpclient.netty") => consoleLogger[IO](minLevel = Level.Warn) case s if s.startsWith("akka.actor") || s.startsWith("wow.doge.mygame") => consoleLogger[IO]() |+| fLogger case _ => //if wildcard case isn't provided, default logger is no-op
consoleLogger[IO]() } }
object StaticLoggerBinder extends StaticLoggerBinder {
var REQUESTED_API_VERSION: String = "1.7"
def getSingleton: StaticLoggerBinder = this
}
|