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.
97 lines
3.4 KiB
97 lines
3.4 KiB
package org.slf4j.impl
|
|
|
|
import scala.concurrent.ExecutionContext
|
|
import scala.concurrent.duration._
|
|
|
|
import _root_.monix.execution.Scheduler
|
|
import cats.effect.Clock
|
|
import cats.effect.ContextShift
|
|
import cats.effect.Effect
|
|
import cats.effect.IO
|
|
import cats.effect.Timer
|
|
import cats.implicits._
|
|
import io.odin._
|
|
import io.odin.json.Formatter
|
|
import io.odin.slf4j.OdinLoggerBinder
|
|
import io.odin.syntax._
|
|
|
|
//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 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 _ => //if wildcard case isn't provided, default logger is no-op
|
|
// consoleLogger[IO]()
|
|
// }
|
|
// private lazy val (defaultConsoleLogger, release1) =
|
|
// consoleLogger[IO](minLevel = Level.Debug)
|
|
// .withAsync(timeWindow = 1.milliseconds)
|
|
// .allocated
|
|
// .unsafeRunSync()
|
|
|
|
private lazy val (mainFileLogger, release2) =
|
|
fileLogger[IO](
|
|
"application-log-2.log",
|
|
Formatter.json,
|
|
minLevel = Level.Debug
|
|
).withAsync(timeWindow = 1.milliseconds)
|
|
.allocated
|
|
.unsafeRunSync()
|
|
|
|
sys.addShutdownHook(release2.unsafeRunSync())
|
|
|
|
// private lazy val (eventBusFileLogger, release3) =
|
|
// fileLogger[IO](
|
|
// "eventbus.log",
|
|
// Formatter.json,
|
|
// minLevel = Level.Debug
|
|
// ).withAsync(timeWindow = 1.milliseconds)
|
|
// .allocated
|
|
// .unsafeRunSync()
|
|
|
|
// {
|
|
// ArraySeq(release1, release2, release3).foreach(r =>
|
|
// sys.addShutdownHook(r.unsafeRunSync())
|
|
// )
|
|
// }
|
|
|
|
val loggers: PartialFunction[String, Logger[IO]] = {
|
|
case "some.external.package.SpecificClass" =>
|
|
//disable noisy external logs
|
|
consoleLogger[IO](minLevel = Level.Debug).withMinimalLevel(Level.Warn)
|
|
case asyncHttpClient
|
|
if asyncHttpClient.startsWith("org.asynchttpclient.netty") =>
|
|
consoleLogger[IO](minLevel = Level.Debug).withMinimalLevel(Level.Warn)
|
|
// case s
|
|
// if s.startsWith(
|
|
// "wow.doge.mygame.subsystems.movement.PlayerMovementEventHandler"
|
|
// ) =>
|
|
// consoleLogger[IO](minLevel = Level.Debug).withMinimalLevel( Level.Trace) //selectively turn on trace logging for specific classes
|
|
// case s if s.startsWith("wow.doge.mygame.events.EventBus") =>
|
|
// consoleLogger[IO](minLevel = Level.Debug).withMinimalLevel(Level.Debug) |+| eventBusFileLogger
|
|
case s if s.startsWith("akka.actor") || s.startsWith("nova.monadic_sfx") =>
|
|
consoleLogger[IO](minLevel = Level.Debug)
|
|
.withMinimalLevel(Level.Debug) |+| mainFileLogger
|
|
case _ => //if wildcard case isn't provided, default logger is no-op
|
|
consoleLogger[IO](minLevel = Level.Debug).withMinimalLevel(Level.Debug)
|
|
}
|
|
}
|
|
|
|
object StaticLoggerBinder extends StaticLoggerBinder {
|
|
|
|
val REQUESTED_API_VERSION: String = "1.7"
|
|
|
|
def getSingleton: StaticLoggerBinder = this
|
|
|
|
}
|