feat(logging): add DEBUG/INFO/WARN logging across services (NCS-72)
Add org.jboss.logging.Logger to AccountService, BotRegistry, BotEventResource, InstanceRegistry, GameRedisSubscriberManager, GameRedisPublisher, GameWebSocketResource, UserWebSocketResource. Replace System.err.println with structured log.warnf in GameRedisSubscriberManager. Silent exception swallow in InstanceRegistry now emits WARN. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,10 @@ import de.nowchess.chess.observer.{GameEvent, Observer}
|
||||
import de.nowchess.chess.registry.GameRegistry
|
||||
import de.nowchess.chess.resource.GameDtoMapper
|
||||
import io.quarkus.redis.datasource.RedisDataSource
|
||||
import org.jboss.logging.Logger
|
||||
|
||||
object GameRedisPublisher:
|
||||
private val log = Logger.getLogger(classOf[GameRedisPublisher])
|
||||
|
||||
class GameRedisPublisher(
|
||||
gameId: String,
|
||||
@@ -23,7 +27,9 @@ class GameRedisPublisher(
|
||||
) extends Observer:
|
||||
|
||||
def onGameEvent(event: GameEvent): Unit =
|
||||
registry.get(gameId).foreach { entry =>
|
||||
try
|
||||
GameRedisPublisher.log.debugf("Publishing game event for game %s", gameId)
|
||||
registry.get(gameId).foreach { entry =>
|
||||
val dto = GameDtoMapper.toGameStateDto(entry, ioClient)
|
||||
val json = objectMapper.writeValueAsString(GameStateEventDto(dto))
|
||||
redis.pubsub(classOf[String]).publish(s2cTopicName, json)
|
||||
@@ -77,3 +83,4 @@ class GameRedisPublisher(
|
||||
writebackEmit(objectMapper.writeValueAsString(wb))
|
||||
if entry.engine.context.result.isDefined then onGameOver(gameId)
|
||||
}
|
||||
catch case ex: Exception => GameRedisPublisher.log.warnf(ex, "Failed to publish game event for game %s", gameId)
|
||||
|
||||
+10
-1
@@ -16,6 +16,7 @@ import jakarta.annotation.PreDestroy
|
||||
import jakarta.enterprise.context.ApplicationScoped
|
||||
import jakarta.enterprise.inject.Instance
|
||||
import jakarta.inject.Inject
|
||||
import org.jboss.logging.Logger
|
||||
import scala.compiletime.uninitialized
|
||||
import scala.util.Try
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -24,6 +25,8 @@ import java.util.function.Consumer
|
||||
@ApplicationScoped
|
||||
class GameRedisSubscriberManager:
|
||||
|
||||
private val log = Logger.getLogger(classOf[GameRedisSubscriberManager])
|
||||
|
||||
// scalafix:off DisableSyntax.var
|
||||
@Inject var redis: RedisDataSource = uninitialized
|
||||
@Inject var registry: GameRegistry = uninitialized
|
||||
@@ -65,11 +68,12 @@ class GameRedisSubscriberManager:
|
||||
)
|
||||
s2cObservers.put(gameId, obs)
|
||||
registry.get(gameId).foreach(_.engine.subscribe(obs))
|
||||
log.debugf("Subscribed to game %s", gameId)
|
||||
|
||||
heartbeatServiceOpt.foreach(_.addGameSubscription(gameId))
|
||||
catch
|
||||
case e: Exception =>
|
||||
System.err.println(s"Warning: Redis subscription failed for game $gameId: ${e.getMessage}")
|
||||
log.warnf(e, "Redis subscription failed for game %s", gameId)
|
||||
()
|
||||
|
||||
def unsubscribeGame(gameId: String): Unit =
|
||||
@@ -81,6 +85,7 @@ class GameRedisSubscriberManager:
|
||||
}
|
||||
|
||||
heartbeatServiceOpt.foreach(_.removeGameSubscription(gameId))
|
||||
log.debugf("Unsubscribed from game %s", gameId)
|
||||
|
||||
private def handleC2sMessage(gameId: String, msg: String): Unit =
|
||||
parseC2sMessage(msg) match
|
||||
@@ -97,6 +102,7 @@ class GameRedisSubscriberManager:
|
||||
}
|
||||
|
||||
private def handleMove(gameId: String, uci: String, playerId: Option[String]): Unit =
|
||||
log.debugf("Processing move %s for game %s by player %s", uci, gameId, playerId.getOrElse("anonymous"))
|
||||
registry.get(gameId).foreach { entry =>
|
||||
entry.mode match
|
||||
case GameMode.Open => entry.engine.processUserInput(uci)
|
||||
@@ -127,6 +133,7 @@ class GameRedisSubscriberManager:
|
||||
|
||||
def batchResubscribeGames(gameIds: java.util.List[String]): Int =
|
||||
gameIds.forEach(subscribeGame)
|
||||
log.infof("Batch resubscribed %d games", gameIds.size())
|
||||
gameIds.size()
|
||||
|
||||
def unsubscribeGames(gameIds: java.util.List[String]): Int =
|
||||
@@ -135,12 +142,14 @@ class GameRedisSubscriberManager:
|
||||
|
||||
def evictGames(gameIds: java.util.List[String]): Int =
|
||||
gameIds.forEach(unsubscribeGame)
|
||||
log.infof("Evicting %d games", gameIds.size())
|
||||
gameIds.size()
|
||||
|
||||
def drainInstance(): Int =
|
||||
val gameIds = new java.util.ArrayList(c2sListeners.keySet())
|
||||
val count = gameIds.size()
|
||||
gameIds.forEach(unsubscribeGame)
|
||||
log.infof("Draining instance, unsubscribing %d games", count)
|
||||
count
|
||||
|
||||
@PreDestroy
|
||||
|
||||
Reference in New Issue
Block a user