Skip to content

Commit

Permalink
Tidy up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnfish committed Dec 20, 2023
1 parent 42712ac commit bfc9903
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
14 changes: 7 additions & 7 deletions devserver/src/main/scala/io/adamnfish/pokerdot/DevServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ object DevServer extends LazyLogging {
seed.toLong
}
.getOrElse(0L)
logger.info(s"[INFO] initial seed: $initialSeed")
logger.info(s"initial seed: $initialSeed")
val rng = new DevRng(initialSeed)

val messagePrinter: Direction => (String, String) => Unit =
if (args.contains("--debug")) {
logger.info("[INFO] debug mode - connection events and messages will be printed")
logger.info("debug mode - connection events and messages will be printed")
logMessage
} else {
noOpMessage
Expand Down Expand Up @@ -69,23 +69,23 @@ object DevServer extends LazyLogging {
}
} match {
case Exit.Success(operation) =>
logger.info(s"[INFO] completed $operation")
logger.info(s"completed $operation")
case Exit.Failure(cause) =>
cause.failures.foreach { fs =>
logger.error(s"[ERROR] error: ${fs.logString}")
logger.error(s"error: ${fs.logString}")
fs.exception.foreach { e =>
logger.error(s"[ERROR] exception: ${e.printStackTrace()}")
logger.error(s"exception: ${e.printStackTrace()}")
}
}
cause.defects.foreach { err =>
logger.error(s"[ERROR] Fatal error: ${err.toString}")
logger.error(s"Fatal error: ${err.getMessage}", err)
}
}
}
})

Runtime.getRuntime.addShutdownHook(new Thread(() => {
logger.info("[INFO] Stopping...")
logger.info("Stopping...")
app.stop()
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AwsMessaging(client: ApiGatewayManagementApiClient) extends Messaging with
}

private def send(playerAddress: PlayerAddress, message: String): Attempt[Unit] = {
logger.debug(s"Message (${playerAddress.address}): $message")
logger.debug(s"Message {${playerAddress.address}}: $message")
val request = PostToConnectionRequest.builder
.connectionId(playerAddress.address)
.data(SdkBytes.fromByteArray(message.getBytes("UTF-8")))
Expand Down
15 changes: 7 additions & 8 deletions lambda/src/main/scala/io/adamnfish/pokerdot/Lambda.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import scala.util.Properties

class Lambda extends LazyLogging {
// initialise AWS clients at start time
val appContextBuilder: (PlayerAddress, AwsContext) => AppContext = {
val appContextBuilder: PlayerAddress => AppContext = {
(for {
// AWS ASK configuration
regionStr <- Properties.envOrNone("REGION")
Expand Down Expand Up @@ -50,7 +50,7 @@ class Lambda extends LazyLogging {
.build()
db = new DynamoDbDatabase(dynamoDbClient, gamesTableName, playersTableName)
rng = new RandomRng
} yield { (playerAddress: PlayerAddress, awsContext: AwsContext) =>
} yield { (playerAddress: PlayerAddress) =>
val messaging = new AwsMessaging(apiGatewayManagementClient)
AppContext(playerAddress, db, messaging, Clock, rng)
}).fold(
Expand All @@ -74,24 +74,24 @@ class Lambda extends LazyLogging {
// ignore this for now
case "$default" =>
val playerAddress = PlayerAddress(event.getRequestContext.getConnectionId)
val appContext = appContextBuilder(playerAddress, awsContext)
val appContext = appContextBuilder(playerAddress)

Unsafe.unsafe { implicit unsafe =>
Runtime.default.unsafe.run(
PokerDot.pokerdot(event.getBody, appContext)
)
} match {
case Exit.Success(operation) =>
logger.info(s"[INFO] completed $operation")
logger.info(s"completed $operation")
case Exit.Failure(cause) =>
cause.failures.foreach { fs =>
logger.error(s"[ERROR] error: ${fs.logString}")
logger.error(s"error: ${fs.logString}")
fs.exception.foreach { e =>
logger.error(s"[ERROR] exception: ${e.printStackTrace()}")
logger.error(s"exception: ${e.printStackTrace()}")
}
}
cause.defects.foreach { err =>
logger.error(s"[ERROR] Fatal error: ${err.toString}")
logger.error(s"Fatal error: ${err.getMessage}", err)
}
}
}
Expand All @@ -103,4 +103,3 @@ class Lambda extends LazyLogging {
response
}
}

0 comments on commit bfc9903

Please sign in to comment.