logging rewrite: part 2
parent
53135d41da
commit
f0741267fb
|
@ -53,7 +53,7 @@ final class Env(
|
|||
domain = Env.api.Net.Domain
|
||||
)), name = RouterName)
|
||||
|
||||
play.api.Logger("boot").info("Preloading modules")
|
||||
lila.log.boot.info("Preloading modules")
|
||||
List(Env.socket,
|
||||
Env.site,
|
||||
Env.tournament,
|
||||
|
|
|
@ -14,7 +14,7 @@ object LilaSocket extends RequestGetter {
|
|||
|
||||
private type AcceptType[A] = RequestHeader => Fu[Either[Result, (Iteratee[A, _], Enumerator[A])]]
|
||||
|
||||
private val logger = play.api.Logger("ratelimit")
|
||||
private val logger = lila.log("ratelimit")
|
||||
|
||||
def rateLimited[A: FrameFormatter](consumer: TokenBucket.Consumer, name: String)(f: AcceptType[A]): WebSocket[A, A] =
|
||||
WebSocket[A, A] { req =>
|
||||
|
|
|
@ -98,18 +98,4 @@ object Opening extends LilaController {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
def importOne = Action.async(parse.json) { implicit req =>
|
||||
env.api.opening.importOne(req.body, ~get("token", req)) map { id =>
|
||||
Ok("kthxbye " + {
|
||||
val url = s"http://lichess.org/training/opening/$id"
|
||||
play.api.Logger("opening import").info(s"${req.remoteAddress} $url")
|
||||
url
|
||||
})
|
||||
} recover {
|
||||
case e =>
|
||||
play.api.Logger("opening import").warn(e.getMessage)
|
||||
BadRequest(e.getMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,16 @@ import lila.memo.AsyncCache
|
|||
|
||||
object Prismic {
|
||||
|
||||
private val logger = (level: Symbol, message: String) => level match {
|
||||
case 'DEBUG => play.api.Logger("prismic") debug message
|
||||
case 'ERROR => play.api.Logger("prismic") error message
|
||||
case _ => play.api.Logger("prismic") info message
|
||||
private val logger = lila.log("prismic")
|
||||
|
||||
val prismicLogger = (level: Symbol, message: String) => level match {
|
||||
case 'DEBUG => logger debug message
|
||||
case 'ERROR => logger error message
|
||||
case _ => logger info message
|
||||
}
|
||||
|
||||
private val fetchPrismicApi = AsyncCache.single[PrismicApi](
|
||||
f = PrismicApi.get(Env.api.PrismicApiUrl, logger = logger),
|
||||
f = PrismicApi.get(Env.api.PrismicApiUrl, logger = prismicLogger),
|
||||
timeToLive = 1 minute)
|
||||
|
||||
def prismicApi = fetchPrismicApi(true)
|
||||
|
@ -42,7 +44,7 @@ object Prismic {
|
|||
}
|
||||
} recover {
|
||||
case e: Exception =>
|
||||
play.api.Logger("prismic").error(s"bookmark:$name $e")
|
||||
logger.error(s"bookmark:$name $e")
|
||||
none
|
||||
}
|
||||
|
||||
|
|
|
@ -369,7 +369,6 @@ GET /api/user controllers.Api.users
|
|||
GET /api/user/:name controllers.Api.user(name: String)
|
||||
GET /api/user/:name/games controllers.Api.userGames(name: String)
|
||||
GET /api/game/:id controllers.Api.game(id: String)
|
||||
POST /api/opening controllers.Opening.importOne
|
||||
GET /api/status controllers.Api.status
|
||||
|
||||
# Misc
|
||||
|
|
|
@ -12,7 +12,7 @@ private[api] final class Cli(bus: lila.common.Bus, renderer: ActorSelection) ext
|
|||
private val logger = lila.log("cli")
|
||||
|
||||
def apply(args: List[String]): Fu[String] = run(args).map(_ + "\n") ~ {
|
||||
_ logFailure ("[cli] " + args.mkString(" ")) foreach { output =>
|
||||
_.logFailure(logger, _ => args mkString " ") foreach { output =>
|
||||
logger.info("%s\n%s".format(args mkString " ", output))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,9 +34,7 @@ object RatingFest {
|
|||
def unrate(game: Game) =
|
||||
(game.whitePlayer.ratingDiff.isDefined || game.blackPlayer.ratingDiff.isDefined) ?? GameRepo.unrate(game.id).void
|
||||
|
||||
def log(x: Any) {
|
||||
play.api.Logger.info(x.toString)
|
||||
}
|
||||
def log(x: Any) = lila.log("ratingFest") info x.toString
|
||||
|
||||
var nb = 0
|
||||
for {
|
||||
|
|
|
@ -15,6 +15,8 @@ private[api] final class RoundApiBalancer(
|
|||
api: RoundApi,
|
||||
nbActors: Int) {
|
||||
|
||||
private val logger = lila.log("round").branch("balancer")
|
||||
|
||||
private object implementation {
|
||||
|
||||
implicit val timeout = makeTimeout seconds 20
|
||||
|
@ -30,14 +32,14 @@ private[api] final class RoundApiBalancer(
|
|||
|
||||
val router = system.actorOf(
|
||||
akka.routing.RoundRobinPool(nbActors).props(Props(new lila.hub.SequentialProvider {
|
||||
val logger = lila.log("round").branch("balancer")
|
||||
val futureTimeout = 20.seconds
|
||||
val logger = RoundApiBalancer.this.logger
|
||||
def process = {
|
||||
case Player(pov, apiVersion, ctx) => {
|
||||
api.player(pov, apiVersion)(ctx) addFailureEffect { e =>
|
||||
play.api.Logger("RoundApiBalancer").error(s"$pov $e")
|
||||
logger.error(pov.toString, e)
|
||||
}
|
||||
}.chronometer.logIfSlow(500, "RoundApiBalancer") { _ => s"inner player $pov" }.result
|
||||
}.chronometer.logIfSlow(500, logger) { _ => s"inner player $pov" }.result
|
||||
case Watcher(pov, apiVersion, tv, analysis, initialFenO, withMoveTimes, withOpening, ctx) =>
|
||||
api.watcher(pov, apiVersion, tv, analysis, initialFenO, withMoveTimes, withOpening)(ctx)
|
||||
case UserAnalysis(pov, pref, initialFen, orientation, owner) =>
|
||||
|
@ -50,11 +52,11 @@ private[api] final class RoundApiBalancer(
|
|||
|
||||
def player(pov: Pov, apiVersion: Int)(implicit ctx: Context): Fu[JsObject] = {
|
||||
router ? Player(pov, apiVersion, ctx) mapTo manifest[JsObject] addFailureEffect { e =>
|
||||
play.api.Logger("RoundApiBalancer").error(s"$pov $e")
|
||||
logger.error(pov.toString, e)
|
||||
}
|
||||
}.chronometer
|
||||
.mon(_.round.api.player)
|
||||
.logIfSlow(500, "RoundApiBalancer") { _ => s"outer player $pov" }
|
||||
.logIfSlow(500, logger) { _ => s"outer player $pov" }
|
||||
.result
|
||||
|
||||
def watcher(pov: Pov, apiVersion: Int, tv: Option[lila.round.OnTv],
|
||||
|
|
|
@ -27,14 +27,14 @@ final class BlogApi(prismicUrl: String, collection: String) {
|
|||
}
|
||||
|
||||
private val cache = BuiltInCache(200)
|
||||
private val logger = (level: Symbol, message: String) => level match {
|
||||
case 'DEBUG => play.api.Logger("prismic") debug message
|
||||
case 'ERROR => play.api.Logger("prismic") error message
|
||||
case _ => play.api.Logger("prismic") info message
|
||||
private val prismicLogger = (level: Symbol, message: String) => level match {
|
||||
case 'DEBUG => logger debug message
|
||||
case 'ERROR => logger error message
|
||||
case _ => logger info message
|
||||
}
|
||||
|
||||
private val fetchPrismicApi = AsyncCache.single[Api](
|
||||
f = Api.get(prismicUrl, cache = cache, logger = logger),
|
||||
f = Api.get(prismicUrl, cache = cache, logger = prismicLogger),
|
||||
timeToLive = 10 seconds)
|
||||
|
||||
def prismicApi = fetchPrismicApi(true)
|
||||
|
|
|
@ -6,15 +6,15 @@ object Chronometer {
|
|||
|
||||
def millis = (nanos / 1000000).toInt
|
||||
|
||||
def logIfSlow(threshold: Int, logger: String)(msg: A => String) = {
|
||||
if (millis >= threshold) play.api.Logger(logger).debug(s"<${millis}ms> ${msg(result)}")
|
||||
def logIfSlow(threshold: Int, logger: lila.log.Logger)(msg: A => String) = {
|
||||
if (millis >= threshold) logger.debug(s"<${millis}ms> ${msg(result)}")
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
case class FuLap[A](lap: Fu[Lap[A]]) {
|
||||
|
||||
def logIfSlow(threshold: Int, logger: String)(msg: A => String) = {
|
||||
def logIfSlow(threshold: Int, logger: lila.log.Logger)(msg: A => String) = {
|
||||
lap.foreach(_.logIfSlow(threshold, logger)(msg))
|
||||
this
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ final class DetectLanguage(url: String, key: String) {
|
|||
)) map { response =>
|
||||
(response.json \ "data" \ "detections").asOpt[List[Detection]] match {
|
||||
case None =>
|
||||
play.api.Logger("DetectLanguage").warn("Invalide service response")
|
||||
lila.log("DetectLanguage").warn(s"Invalide service response ${response.json}")
|
||||
None
|
||||
case Some(res) => res.filter(_.isReliable)
|
||||
.sortBy(-_.confidence)
|
||||
|
@ -33,7 +33,7 @@ final class DetectLanguage(url: String, key: String) {
|
|||
}
|
||||
} recover {
|
||||
case e: Exception =>
|
||||
play.api.Logger("detect language").warn(e.getMessage)
|
||||
lila.log("DetectLanguage").warn(e.getMessage, e)
|
||||
Lang("en").some
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ trait PackageObject extends Steroids with WithFuture {
|
|||
|
||||
implicit final class LilaPimpedString(s: String) {
|
||||
|
||||
def boot[A](v: => A): A = { play.api.Logger("boot").info(s); v }
|
||||
def boot[A](v: => A): A = { lila.log.boot.info(s); v }
|
||||
}
|
||||
|
||||
implicit final class LilaPimpedValid[A](v: Valid[A]) {
|
||||
|
@ -157,10 +157,9 @@ trait WithPlay { self: PackageObject =>
|
|||
def flatFold[B](fail: Exception => Fu[B], succ: A => Fu[B]): Fu[B] =
|
||||
fua flatMap succ recoverWith { case e: Exception => fail(e) }
|
||||
|
||||
def logFailure(logger: => String, msg: Exception => String): Fu[A] = fua ~ (_ onFailure {
|
||||
case e: Exception => play.api.Logger(logger).warn(msg(e))
|
||||
})
|
||||
def logFailure(logger: => String): Fu[A] = logFailure(logger, _.toString)
|
||||
def logFailure(logger: => lila.log.Logger, msg: Exception => String): Fu[A] =
|
||||
addFailureEffect { e => logger.warn(msg(e), e) }
|
||||
def logFailure(logger: => lila.log.Logger): Fu[A] = logFailure(logger, _.toString)
|
||||
|
||||
def addEffect(effect: A => Unit) = fua ~ (_ foreach effect)
|
||||
|
||||
|
|
|
@ -2,31 +2,14 @@ package lila
|
|||
|
||||
object log {
|
||||
|
||||
def apply(name: String): Logger = new Logger(name, identity)
|
||||
def apply(name: String): Logger = new Logger(name)
|
||||
|
||||
final class Logger(
|
||||
name: String,
|
||||
transformer: String => String) extends play.api.LoggerLike {
|
||||
val boot = apply("boot")
|
||||
|
||||
final class Logger(name: String) extends play.api.LoggerLike {
|
||||
|
||||
val logger = org.slf4j.LoggerFactory getLogger name
|
||||
|
||||
def map(trans: String => String) = new Logger(
|
||||
name = name,
|
||||
transformer = msg => trans(transformer(msg)))
|
||||
|
||||
def prefix(p: String) = map(msg => s"$p: $msg")
|
||||
|
||||
def branch(childName: String) = new Logger(
|
||||
name = s"$name.$childName",
|
||||
transformer = transformer)
|
||||
|
||||
override def debug(message: => String) = super.debug(transformer(message))
|
||||
override def debug(message: => String, error: => Throwable) = super.debug(transformer(message), error)
|
||||
override def info(message: => String) = super.info(transformer(message))
|
||||
override def info(message: => String, error: => Throwable) = super.info(transformer(message), error)
|
||||
override def warn(message: => String) = super.warn(transformer(message))
|
||||
override def warn(message: => String, error: => Throwable) = super.warn(transformer(message), error)
|
||||
override def error(message: => String) = super.error(transformer(message))
|
||||
override def error(message: => String, error: => Throwable) = super.error(transformer(message), error)
|
||||
def branch(childName: String) = new Logger(name = s"$name.$childName")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,5 +320,5 @@ object mon {
|
|||
|
||||
private def nodots(s: String) = s.replace(".", "_")
|
||||
|
||||
private val logger = play.api.Logger("monitor")
|
||||
private val logger = lila.log("monitor")
|
||||
}
|
||||
|
|
|
@ -170,5 +170,5 @@ private final class ExplorerIndexer(
|
|||
}
|
||||
})
|
||||
|
||||
private val logger = play.api.Logger("explorer")
|
||||
private val logger = lila.log("explorer")
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ private object AnalysisBuilder {
|
|||
fufail(_),
|
||||
replay => UciToPgn(replay, uciAnalysis) match {
|
||||
case (analysis, errors) =>
|
||||
errors foreach { e => log.warn(s"[UciToPgn] $debug $e") }
|
||||
errors foreach { e => logger.warn(s"[UciToPgn] $debug $e") }
|
||||
if (analysis.valid) {
|
||||
if (analysis.emptyRatio >= 1d / 10)
|
||||
fufail(s"Analysis $debug has ${analysis.nbEmptyInfos} empty infos out of ${analysis.infos.size}")
|
||||
|
|
|
@ -27,7 +27,7 @@ private final class Cleaner(
|
|||
moveDb.find(_ acquiredBefore since).map { move =>
|
||||
moveDb updateOrGiveUp move.timeout
|
||||
clientTimeout(move)
|
||||
log.warn(s"Timeout move ${move.game.id}")
|
||||
logger.warn(s"Timeout move ${move.game.id}")
|
||||
}
|
||||
scheduleMoves
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ private final class Cleaner(
|
|||
}.map { ana =>
|
||||
repo.updateOrGiveUpAnalysis(ana.timeout) >>- {
|
||||
clientTimeout(ana)
|
||||
log.warn(s"Timeout analysis ${ana.game.id}")
|
||||
logger.warn(s"Timeout analysis ${ana.game.id}")
|
||||
}
|
||||
}.sequenceFu.void
|
||||
} andThenAnyway scheduleAnalysis
|
||||
|
@ -48,7 +48,7 @@ private final class Cleaner(
|
|||
private def clientTimeout(work: Work) = work.acquiredByKey ?? repo.getClient foreach {
|
||||
_ foreach { client =>
|
||||
monitor.timeout(work, client)
|
||||
log.warn(s"Timeout client ${client.fullId}")
|
||||
logger.warn(s"Timeout client ${client.fullId}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,15 +38,15 @@ final class FishnetApi(
|
|||
case Skill.All => acquireMove(client) orElse acquireAnalysis(client)
|
||||
}).chronometer
|
||||
.mon(_.fishnet.acquire time client.skill.key)
|
||||
.logIfSlow(100, "fishnet")(_ => s"acquire ${client.skill}")
|
||||
.logIfSlow(100, logger)(_ => s"acquire ${client.skill}")
|
||||
.result
|
||||
.withTimeout(1 second, AcquireTimeout)
|
||||
.recover {
|
||||
case e: FutureSequencer.Timeout =>
|
||||
log.warn(s"[${client.skill}] Fishnet.acquire ${e.getMessage}")
|
||||
logger.warn(s"[${client.skill}] Fishnet.acquire ${e.getMessage}")
|
||||
none
|
||||
case AcquireTimeout =>
|
||||
log.warn(s"[${client.skill}] Fishnet.acquire timed out")
|
||||
logger.warn(s"[${client.skill}] Fishnet.acquire timed out")
|
||||
none
|
||||
} >>- monitor.acquire(client)
|
||||
|
||||
|
@ -77,7 +77,7 @@ final class FishnetApi(
|
|||
moveDb.transaction { implicit txn =>
|
||||
moveDb.get(workId).filter(_ isAcquiredBy client) match {
|
||||
case None =>
|
||||
log.warn(s"Received unknown or unacquired move $workId by ${client.fullId}")
|
||||
logger.warn(s"Received unknown or unacquired move $workId by ${client.fullId}")
|
||||
case Some(work) => data.move.uci match {
|
||||
case Some(uci) =>
|
||||
monitor.move(work, client)
|
||||
|
@ -85,35 +85,35 @@ final class FishnetApi(
|
|||
moveDb.delete(work)
|
||||
case _ =>
|
||||
monitor.failure(work, client)
|
||||
log.warn(s"Received invalid move ${data.move} by ${client.fullId}")
|
||||
logger.warn(s"Received invalid move ${data.move} by ${client.fullId}")
|
||||
moveDb.updateOrGiveUp(work.invalid)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.chronometer.mon(_.fishnet.move.post)
|
||||
.logIfSlow(100, "fishnet")(_ => "post move").result
|
||||
.logIfSlow(100, logger)(_ => "post move").result
|
||||
|
||||
def postAnalysis(workId: Work.Id, client: Client, data: JsonApi.Request.PostAnalysis): Funit = sequencer {
|
||||
repo.getAnalysis(workId).map(_.filter(_ isAcquiredBy client)) flatMap {
|
||||
case None =>
|
||||
log.warn(s"Received unknown or unacquired analysis $workId by ${client.fullId}")
|
||||
logger.warn(s"Received unknown or unacquired analysis $workId by ${client.fullId}")
|
||||
fuccess(none)
|
||||
case Some(work) => AnalysisBuilder(client, work, data) flatMap { analysis =>
|
||||
monitor.analysis(work, client, data)
|
||||
repo.deleteAnalysis(work) inject analysis.some
|
||||
} recoverWith {
|
||||
case e: AnalysisBuilder.GameIsGone =>
|
||||
log.warn(s"Game ${work.game.id} was deleted by ${work.sender} before analysis completes")
|
||||
logger.warn(s"Game ${work.game.id} was deleted by ${work.sender} before analysis completes")
|
||||
monitor.analysis(work, client, data)
|
||||
repo.deleteAnalysis(work) inject none
|
||||
case e: Exception =>
|
||||
monitor.failure(work, client)
|
||||
log.warn(s"Received invalid analysis $workId by ${client.fullId}: ${e.getMessage}")
|
||||
logger.warn(s"Received invalid analysis $workId by ${client.fullId}: ${e.getMessage}")
|
||||
repo.updateOrGiveUpAnalysis(work.invalid) inject none
|
||||
}
|
||||
}
|
||||
}.chronometer.mon(_.fishnet.analysis.post)
|
||||
.logIfSlow(200, "fishnet") { res =>
|
||||
.logIfSlow(200, logger) { res =>
|
||||
s"post analysis for ${res.??(_.id)}"
|
||||
}.result
|
||||
.flatMap { _ ?? saveAnalysis }
|
||||
|
|
|
@ -43,7 +43,7 @@ private final class FishnetRepo(
|
|||
def getAnalysis(id: Work.Id) = analysisColl.find(selectWork(id)).one[Work.Analysis]
|
||||
def updateAnalysis(ana: Work.Analysis) = analysisColl.update(selectWork(ana.id), ana).void
|
||||
def deleteAnalysis(ana: Work.Analysis) = analysisColl.remove(selectWork(ana.id)).void
|
||||
def giveUpAnalysis(ana: Work.Analysis) = deleteAnalysis(ana) >>- log.warn(s"Give up on analysis $ana")
|
||||
def giveUpAnalysis(ana: Work.Analysis) = deleteAnalysis(ana) >>- logger.warn(s"Give up on analysis $ana")
|
||||
def updateOrGiveUpAnalysis(ana: Work.Analysis) = if (ana.isOutOfTries) giveUpAnalysis(ana) else updateAnalysis(ana)
|
||||
def countAnalysis(acquired: Boolean) = analysisColl.count(BSONDocument(
|
||||
"acquired" -> BSONDocument("$exists" -> acquired)
|
||||
|
|
|
@ -39,7 +39,7 @@ private final class MoveDB {
|
|||
|
||||
def updateOrGiveUp(move: Move) = transaction { implicit txn =>
|
||||
if (move.isOutOfTries) {
|
||||
log.warn(s"Give up on move $move")
|
||||
logger.warn(s"Give up on move $move")
|
||||
delete(move)
|
||||
}
|
||||
else update(move)
|
||||
|
|
|
@ -2,5 +2,5 @@ package lila
|
|||
|
||||
package object fishnet extends PackageObject with WithPlay {
|
||||
|
||||
val log = play.api.Logger("fishnet")
|
||||
private[fishnet] def logger = lila.log("fishnet")
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ object FutureSequencer {
|
|||
}
|
||||
|
||||
private final class FSequencer(
|
||||
logger: lila.log.Logger,
|
||||
logger: lila.log.Logger,
|
||||
receiveTimeout: Option[FiniteDuration],
|
||||
executionTimeout: Option[FiniteDuration] = None) extends Actor {
|
||||
|
||||
|
@ -78,7 +78,7 @@ object FutureSequencer {
|
|||
f(queue.size)
|
||||
self ! Done
|
||||
case x =>
|
||||
logger.warn(s"[FSequencer] Unsupported message $x")
|
||||
logger.branch("FutureSequencer").warn(s"Unsupported message $x")
|
||||
self ! Done
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ final class Sequencer(
|
|||
self ! Done
|
||||
}
|
||||
promiseOption foreach (_ completeWith future)
|
||||
case x => logger.warn(s"[Sequencer] Unsupported message $x")
|
||||
case x => logger.branch("Sequencer").warn(s"Unsupported message $x")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ trait SequentialProvider extends Actor {
|
|||
private def debugQueue {
|
||||
if (debug) queue.size match {
|
||||
case size if (size == 50 || (size >= 100 && size % 100 == 0)) =>
|
||||
logger.warn(s"Seq[$name] queue = $size, mps = ${windowCount.get}")
|
||||
logger.branch("SequentialProvider").warn(s"Seq[$name] queue = $size, mps = ${windowCount.get}")
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ trait SequentialProvider extends Actor {
|
|||
(process orElse fallback)(msg)
|
||||
.withTimeout(futureTimeout, LilaException(s"Sequential provider timeout: $futureTimeout"))(context.system)
|
||||
.pipeTo(replyTo) andThenAnyway { self ! Done }
|
||||
case x => logger.warn(s"SequentialProvider should never have received $x")
|
||||
case x => logger.branch("SequentialProvider").warn(s"should never have received $x")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ object HookRepo {
|
|||
def findCompatible(hook: Hook): Vector[Hook] = hooks filter (_ compatibleWith hook)
|
||||
|
||||
def truncateIfNeeded = if (size >= hardLimit) {
|
||||
play.api.Logger("lobby").warn(s"Found ${size} hooks, cleaning up!")
|
||||
logger.warn(s"Found ${size} hooks, cleaning up!")
|
||||
cleanupOld
|
||||
hooks = hooks.take(hardLimit / 2)
|
||||
}
|
||||
|
|
|
@ -105,10 +105,10 @@ private[lobby] final class Lobby(
|
|||
case Broom =>
|
||||
HookRepo.truncateIfNeeded
|
||||
(socket ? GetUids mapTo manifest[SocketUids]).chronometer
|
||||
.logIfSlow(100, "lobby") { r => s"GetUids size=${r.uids.size}" }
|
||||
.logIfSlow(100, logger) { r => s"GetUids size=${r.uids.size}" }
|
||||
.mon(_.lobby.socket.getUids)
|
||||
.result
|
||||
.logFailure("lobby", err => s"broom cannot get uids from socket: $err")
|
||||
.logFailure(logger, err => s"broom cannot get uids from socket: $err")
|
||||
.addFailureEffect { _ =>
|
||||
scheduleBroom
|
||||
} pipeTo self
|
||||
|
@ -120,10 +120,10 @@ private[lobby] final class Lobby(
|
|||
_.createdAt isBefore createdBefore
|
||||
} ++ HookRepo.cleanupOld
|
||||
}.toSet
|
||||
// play.api.Logger("lobby").debug(
|
||||
// logger.debug(
|
||||
// s"broom uids:${uids.size} before:${createdBefore} hooks:${hooks.map(_.id)}")
|
||||
if (hooks.nonEmpty) {
|
||||
// play.api.Logger("lobby").debug(s"remove ${hooks.size} hooks")
|
||||
// logger.debug(s"remove ${hooks.size} hooks")
|
||||
self ! RemoveHooks(hooks)
|
||||
}
|
||||
scheduleBroom
|
||||
|
|
|
@ -2,4 +2,7 @@ package lila
|
|||
|
||||
import lila.socket.WithSocket
|
||||
|
||||
package object lobby extends PackageObject with WithPlay with WithSocket
|
||||
package object lobby extends PackageObject with WithPlay with WithSocket {
|
||||
|
||||
private[lobby] def logger = lila.log("lobby")
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ object MixedCache {
|
|||
val sync = Builder.cache[K, V](
|
||||
timeToLive,
|
||||
(k: K) => async(k) await makeTimeout(awaitTime))
|
||||
new MixedCache(sync, default, invalidate(async, sync) _, logger prefix "MixedCache")
|
||||
new MixedCache(sync, default, invalidate(async, sync) _, logger branch "MixedCache")
|
||||
}
|
||||
|
||||
def single[V](
|
||||
|
@ -52,6 +52,6 @@ object MixedCache {
|
|||
val sync = Builder.cache[Boolean, V](
|
||||
timeToLive,
|
||||
(_: Boolean) => async(true) await makeTimeout(awaitTime))
|
||||
new MixedCache(sync, _ => default, invalidate(async, sync) _, logger prefix "MixedCache")
|
||||
new MixedCache(sync, _ => default, invalidate(async, sync) _, logger branch "MixedCache")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ final class RateLimit(nb: Int, duration: Duration, name: String) {
|
|||
|
||||
private def makeClearAt = nowMillis + duration.toMillis
|
||||
|
||||
private val logger = play.api.Logger("ratelimit")
|
||||
private val logger = lila.log("ratelimit")
|
||||
|
||||
logger.info(s"[start] $name ($nb/$duration)")
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ final class ModlogApi {
|
|||
|
||||
private def add(m: Modlog): Funit = {
|
||||
lila.mon.mod.log.create()
|
||||
play.api.Logger("ModApi").info(m.toString)
|
||||
lila.log("mod").info(m.toString)
|
||||
$insert(m)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ private[opening] final class Finisher(
|
|||
system.updateRatings(results)
|
||||
}
|
||||
catch {
|
||||
case e: Exception => play.api.Logger("Opening trainer").error(e.getMessage)
|
||||
case e: Exception => lila.log("opening").error("update ratings", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ object UserInfos {
|
|||
new UserInfos(user, makeHistory(attempts), makeChart(attempts))
|
||||
} recover {
|
||||
case e: Exception =>
|
||||
play.api.Logger("Opening UserInfos").error(e.getMessage)
|
||||
lila.log("opening").error("user infos", e)
|
||||
new UserInfos(user, Nil, JsArray())
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ final class PlaybanApi(
|
|||
} map2 UserRecordBSONHandler.read flatMap {
|
||||
case None => fufail(s"can't find record for user $userId")
|
||||
case Some(record) => legiferate(record)
|
||||
} logFailure "PlaybanApi"
|
||||
} logFailure lila.log("playban")
|
||||
|
||||
private def legiferate(record: UserRecord): Funit = record.newBan ?? { ban =>
|
||||
coll.update(
|
||||
|
|
|
@ -15,8 +15,6 @@ private final class ApplePush(
|
|||
|
||||
private val actor = system.actorOf(Props(classOf[ApnsActor], certificate, password))
|
||||
|
||||
private val logger = play.api.Logger("push")
|
||||
|
||||
def apply(userId: String)(data: => PushApi.Data): Funit =
|
||||
getDevice(userId) map {
|
||||
_ foreach { device =>
|
||||
|
@ -41,8 +39,6 @@ private final class ApnsActor(certificate: InputStream, password: String) extend
|
|||
|
||||
import com.relayrides.pushy.apns._, util._
|
||||
|
||||
val logger = play.api.Logger("push")
|
||||
|
||||
var manager: PushManager[SimpleApnsPushNotification] = _
|
||||
|
||||
def getManager = Option(manager) getOrElse {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
package lila
|
||||
|
||||
package object push extends PackageObject with WithPlay
|
||||
package object push extends PackageObject with WithPlay {
|
||||
|
||||
private[push] def logger = lila.log("push")
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ private[puzzle] final class Daily(
|
|||
|
||||
private def find: Fu[Option[DailyPuzzle]] = (findCurrent orElse findNew) recover {
|
||||
case e: Exception =>
|
||||
play.api.Logger("daily puzzle").error(e.toString)
|
||||
logger.error("find daily", e)
|
||||
none
|
||||
} flatMap {
|
||||
case Some(puzzle) => makeDaily(puzzle)
|
||||
|
@ -40,7 +40,7 @@ private[puzzle] final class Daily(
|
|||
}
|
||||
} recover {
|
||||
case e: Exception =>
|
||||
play.api.Logger("daily puzzle").warn(e.getMessage)
|
||||
logger.warn("make daily", e)
|
||||
none
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ private[puzzle] final class Finisher(
|
|||
system.updateRatings(results)
|
||||
}
|
||||
catch {
|
||||
case e: Exception => play.api.Logger("Puzzle finisher").error(e.getMessage)
|
||||
case e: Exception => logger.error("finisher", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ object UserInfos {
|
|||
new UserInfos(user, makeHistory(attempts), makeChart(attempts))
|
||||
} recover {
|
||||
case e: Exception =>
|
||||
play.api.Logger("Puzzle UserInfos").error(e.getMessage)
|
||||
logger.error("user infos", e)
|
||||
new UserInfos(user, Nil, JsArray())
|
||||
}
|
||||
|
||||
|
|
|
@ -5,4 +5,6 @@ package object puzzle extends PackageObject with WithPlay {
|
|||
type PuzzleId = Int
|
||||
type AttemptId = Int
|
||||
type Lines = List[Line]
|
||||
|
||||
private[puzzle] def logger = lila.log("puzzle")
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ case class Perf(
|
|||
}
|
||||
|
||||
def addOrReset(monitor: lila.mon.IncPath, msg: => String)(r: Rating, date: DateTime): Perf = add(r, date) | {
|
||||
play.api.Logger.error(s"Crazy Glicko2 $msg")
|
||||
lila.log("rating").error(s"Crazy Glicko2 $msg")
|
||||
lila.mon.incPath(monitor)()
|
||||
add(Glicko.default, date)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ private[round] final class CheatDetector(reporter: ActorSelection) {
|
|||
_ ?? { mirror =>
|
||||
mirror.players map (p => p -> p.userId) collectFirst {
|
||||
case (player, Some(userId)) => game.players find (_.userId == player.userId) map { cheater =>
|
||||
play.api.Logger("cheat detector").info(s"${cheater.color} ($userId) @ ${game.id} uses ${mirror.id}")
|
||||
lila.log("cheat").info(s"${cheater.color} ($userId) @ ${game.id} uses ${mirror.id}")
|
||||
if (createReport) reporter ! lila.hub.actorApi.report.Cheater(userId,
|
||||
s"Cheat detected on ${gameUrl(game.id)}, using lichess AI: ${gameUrl(mirror.id)}")
|
||||
cheater.color
|
||||
|
|
|
@ -3,7 +3,6 @@ package lila.round
|
|||
import chess.{ Speed }
|
||||
import org.goochjs.glicko2._
|
||||
import org.joda.time.DateTime
|
||||
import play.api.Logger
|
||||
|
||||
import lila.game.{ GameRepo, Game, Pov, PerfPicker }
|
||||
import lila.history.HistoryApi
|
||||
|
@ -119,7 +118,7 @@ final class PerfsUpdater(
|
|||
system.updateRatings(results)
|
||||
}
|
||||
catch {
|
||||
case e: Exception => logger.error(e.getMessage)
|
||||
case e: Exception => logger.error("update ratings", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,6 +158,4 @@ final class PerfsUpdater(
|
|||
correspondence = r(PT.Correspondence, perfs.correspondence, perfs1.correspondence))
|
||||
if (isStd) perfs2.updateStandard else perfs2
|
||||
}
|
||||
|
||||
private def logger = play.api.Logger("PerfsUpdater")
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@ private[round] final class Round(
|
|||
}
|
||||
}
|
||||
|
||||
val logger = play.api.Logger("round")
|
||||
|
||||
def process = {
|
||||
|
||||
case ReceiveTimeout => fuccess {
|
||||
|
|
|
@ -65,7 +65,7 @@ final class ShutupApi(
|
|||
upsert = true).map(_.value) map2 UserRecordBSONHandler.read flatMap {
|
||||
case None => fufail(s"can't find user record for $userId")
|
||||
case Some(userRecord) => legiferate(userRecord)
|
||||
} logFailure "ShutupApi"
|
||||
} logFailure lila.log("shutup")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ private final class LeaderboardIndexer(
|
|||
Iteratee.foldM[Seq[Entry], Int](0) {
|
||||
case (number, entries) =>
|
||||
if (number % 10000 == 0)
|
||||
play.api.Logger("tournament").info(s"Generating leaderboards... $number")
|
||||
logger.info(s"Generating leaderboards... $number")
|
||||
saveEntries(entries) inject (number + entries.size)
|
||||
}
|
||||
}.void
|
||||
|
|
|
@ -134,7 +134,7 @@ object PlayerRepo {
|
|||
coll.find(selectTour(tourId) ++ BSONDocument(
|
||||
"uid" -> BSONDocument("$in" -> userIds)
|
||||
)).cursor[Player]().collect[List]()
|
||||
.chronometer.logIfSlow(200, "tourpairing") { players =>
|
||||
.chronometer.logIfSlow(200, logger) { players =>
|
||||
s"PlayerRepo.byTourAndUserIds $tourId ${userIds.size} user IDs, ${players.size} players"
|
||||
}.result
|
||||
|
||||
|
@ -156,7 +156,7 @@ object PlayerRepo {
|
|||
def rankedByTourAndUserIds(tourId: String, userIds: Iterable[String], ranking: Ranking): Fu[RankedPlayers] =
|
||||
byTourAndUserIds(tourId, userIds).map { rankPlayers(_, ranking) }
|
||||
.chronometer
|
||||
.logIfSlow(200, "tourpairing") { players =>
|
||||
.logIfSlow(200, logger) { players =>
|
||||
s"PlayerRepo.rankedByTourAndUserIds $tourId ${userIds.size} user IDs, ${ranking.size} ranking, ${players.size} players"
|
||||
}.result
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ private[tournament] final class TournamentApi(
|
|||
tour.system.pairingSystem.createPairings(tour, users, ranking).flatMap {
|
||||
case Nil => funit
|
||||
case pairings if nowMillis - startAt > 1000 =>
|
||||
play.api.Logger("tourpairing").warn(s"Give up making http://lichess.org/tournament/${tour.id} ${pairings.size} pairings in ${nowMillis - startAt}ms")
|
||||
pairingLogger.warn(s"Give up making http://lichess.org/tournament/${tour.id} ${pairings.size} pairings in ${nowMillis - startAt}ms")
|
||||
funit
|
||||
case pairings => pairings.map { pairing =>
|
||||
PairingRepo.insert(pairing) >>
|
||||
|
@ -80,7 +80,7 @@ private[tournament] final class TournamentApi(
|
|||
val time = nowMillis - startAt
|
||||
lila.mon.tournament.pairing.createTime(time.toInt)
|
||||
if (time > 100)
|
||||
play.api.Logger("tourpairing").debug(s"Done making http://lichess.org/tournament/${tour.id} in ${time}ms")
|
||||
pairingLogger.debug(s"Done making http://lichess.org/tournament/${tour.id} in ${time}ms")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ object PairingSystem extends AbstractPairingSystem {
|
|||
UserRepo.firstGetsWhite(prep.user1.some, prep.user2.some) map prep.toPairing
|
||||
}.sequenceFu
|
||||
} yield pairings
|
||||
}.chronometer.logIfSlow(500, "tourpairing") { pairings =>
|
||||
}.chronometer.logIfSlow(500, pairingLogger) { pairings =>
|
||||
s"createPairings ${url(tour.id)} ${pairings.size} pairings"
|
||||
}.result
|
||||
|
||||
|
@ -60,7 +60,7 @@ object PairingSystem extends AbstractPairingSystem {
|
|||
case Nil => Nil
|
||||
}
|
||||
}
|
||||
}.chronometer.logIfSlow(200, "tourpairing") { preps =>
|
||||
}.chronometer.logIfSlow(200, pairingLogger) { preps =>
|
||||
s"makePreps ${url(data.tour.id)} ${users.size} users, ${preps.size} preps"
|
||||
}.result
|
||||
|
||||
|
@ -148,7 +148,7 @@ object PairingSystem extends AbstractPairingSystem {
|
|||
case (rp0, rp1) => rp0.player -> rp1.player
|
||||
}
|
||||
case _ =>
|
||||
logger.warn("Could not make smart pairings for arena tournament")
|
||||
pairingLogger.warn("Could not make smart pairings for arena tournament")
|
||||
players map (_.player) grouped 2 collect {
|
||||
case List(p1, p2) => (p1, p2)
|
||||
} toList
|
||||
|
@ -156,7 +156,7 @@ object PairingSystem extends AbstractPairingSystem {
|
|||
}) map {
|
||||
Pairing.prep(tour, _)
|
||||
}
|
||||
if (!continue) play.api.Logger("tourpairing").info(s"smartPairings cutoff! [${nowMillis - startAt}ms] ${url(data.tour.id)} ${players.size} players, ${preps.size} preps")
|
||||
if (!continue) pairingLogger.info(s"smartPairings cutoff! [${nowMillis - startAt}ms] ${url(data.tour.id)} ${players.size} players, ${preps.size} preps")
|
||||
preps
|
||||
}
|
||||
|
||||
|
|
|
@ -14,5 +14,7 @@ package object tournament extends PackageObject with WithPlay with WithSocket {
|
|||
|
||||
private[tournament]type Waiting = Map[String, Int]
|
||||
|
||||
private[tournament] def logger = lila.log("tournament")
|
||||
private[tournament] val logger = lila.log("tournament")
|
||||
|
||||
private[tournament] val pairingLogger = logger branch "pairing"
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ final class StreamerList(
|
|||
}.foldLeft(List.empty[Streamer] -> List.empty[Exception]) {
|
||||
case ((res, err), Success(r)) => (r :: res, err)
|
||||
case ((res, err), Failure(e: Exception)) =>
|
||||
play.api.Logger("streamer").warn(e.getMessage)
|
||||
lila.log("tv").warn("streamer", e)
|
||||
(res, e :: err)
|
||||
case (_, Failure(e)) => throw e
|
||||
}
|
||||
|
|
|
@ -28,5 +28,5 @@ final class LightUserApi(coll: Coll) {
|
|||
).one[LightUser],
|
||||
timeToLive = 20 minutes,
|
||||
default = id => LightUser(id, id, None).some,
|
||||
logger = logger prefix "LightUserApi")
|
||||
logger = logger branch "LightUserApi")
|
||||
}
|
||||
|
|
|
@ -40,11 +40,11 @@ final class Env(
|
|||
|
||||
if (!isDev) {
|
||||
scheduler.effect(SheetDelay, "video update from sheet") {
|
||||
sheet.fetchAll logFailure "video sheet"
|
||||
sheet.fetchAll logFailure logger
|
||||
}
|
||||
|
||||
scheduler.effect(YoutubeDelay, "video update from youtube") {
|
||||
youtube.updateAll logFailure "video youtube"
|
||||
youtube.updateAll logFailure logger
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue