Skip to content

Commit c94cdf3

Browse files
committed
refactor: migrate all logger calls to new braces style
1 parent df4e109 commit c94cdf3

File tree

8 files changed

+28
-26
lines changed

8 files changed

+28
-26
lines changed

src/main/kotlin/sc/gui/GuiApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ open class ServerApp(primaryView: KClass<out UIComponent>) : App(primaryView, Ap
3131
AppModel.save()
3232
super.stop()
3333
server.stopServer()
34-
logger.info("App stopped, Terminating")
34+
logger.info { "App stopped, Terminating" }
3535
}
3636

3737
init {

src/main/kotlin/sc/gui/LobbyManager.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LobbyManager(host: String, port: Int): Controller(), Consumer<ResponsePack
3939
private val client: AdminClient = try {
4040
LobbyClient(host, port).authenticate(Configuration.get(Configuration.PASSWORD_KEY), this)
4141
} catch (e: ConnectException) {
42-
logger.error("Could not connect to server: " + e.message)
42+
logger.error(e) { "Could not connect to server: " + e.message }
4343
exitProcess(1)
4444
}
4545

@@ -53,7 +53,7 @@ class LobbyManager(host: String, port: Int): Controller(), Consumer<ResponsePack
5353
player.joinGameRoom(packet.roomId)
5454
} else {
5555
if (reservationIndex >= packet.reservations.size) {
56-
logger.warn("More players than reservations, left with {}", pendingPlayers)
56+
logger.warn { "More players than reservations, left with $pendingPlayers" }
5757
return@removeAll false
5858
}
5959
player.joinGameWithReservation(packet.reservations[reservationIndex++])
@@ -62,7 +62,7 @@ class LobbyManager(host: String, port: Int): Controller(), Consumer<ResponsePack
6262
}
6363
}
6464
is ErrorPacket -> {
65-
logger.error("$packet")
65+
logger.error { "$packet" }
6666
// if (packet.originalRequest !is CancelRequest)
6767
Platform.runLater {
6868
error("Fehler in der Kommunikation mit dem Server", packet.toString()).setOnCloseRequest {
@@ -81,11 +81,11 @@ class LobbyManager(host: String, port: Int): Controller(), Consumer<ResponsePack
8181
gameFlowController.controller = client.control(roomId)
8282
subscribe<NewGameState>(1) { fire(GameReadyEvent()) }
8383
client.observe(roomId) { msg ->
84-
logger.trace("New RoomMessage in {}: {}", roomId, msg)
85-
when (msg) {
84+
logger.trace { "New RoomMessage in $roomId: $msg" }
85+
when(msg) {
8686
is MementoMessage -> fire(NewGameState(msg.state))
8787
is GameResult -> if(gameFlowController.controller != null) fire(GameOverEvent(msg))
88-
is ErrorMessage -> logger.warn("Error in $roomId: $msg")
88+
is ErrorMessage -> logger.warn { "Error in $roomId: $msg" }
8989
is GamePaused -> fire(GamePausedEvent(msg.paused))
9090
}
9191
}

src/main/kotlin/sc/gui/controller/AppController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class AppController: Controller() {
3636

3737
private fun changeViewTo(newView: ViewType) {
3838
val current = model.currentView.get()
39-
logger.debug("Requested View change from ${current.name} -> $newView")
39+
logger.debug { "Requested View change from ${current.name} -> $newView" }
4040
if (current == newView) {
41-
logger.warn("Noop view change request!")
41+
logger.warn { "Noop view change request!" }
4242
return
4343
}
4444
find(current.view).replaceWith(newView.view)

src/main/kotlin/sc/gui/controller/GameFlowController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class GameFlowController: Controller() {
9999
subscribe<NewGameState> { event ->
100100
val state = event.gameState
101101
history.add(state)
102-
logger.debug("New state: {}", state)
102+
logger.debug { "New state: $state" }
103103
gameModel.run {
104104
if(stepController || gameState.value == null || gameResult.value != null) {
105105
gameResult.set(null)
@@ -117,7 +117,7 @@ class GameFlowController: Controller() {
117117
throw ReplayLoaderException("Trying to load replay into a running game")
118118
val result = loader.loadHistory()
119119
history.addAll(result.first)
120-
logger.debug("Loaded {} states from {}", history.size, loader)
120+
logger.debug { "Loaded ${history.size} states from $loader" }
121121
if(history.isEmpty())
122122
throw ReplayLoaderException("Replay history from $loader is empty")
123123

src/main/kotlin/sc/gui/util/DesktopUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ fun browse(file: File) {
2121
fun <T> T.openDesktop(action: Desktop.Action, open: Desktop.(T) -> Unit) {
2222
val desktop = Desktop.getDesktop()
2323
if(desktop.isSupported(action)) {
24-
logger.debug("Opening {} on {}", this, desktop)
24+
logger.debug { "Opening $this on $desktop" }
2525
open(desktop, this)
2626
} else {
27-
logger.debug("Opening {} with xdg-open", this)
27+
logger.debug { "Opening $this with xdg-open" }
2828
try {
2929
ProcessBuilder("xdg-open", this.toString()).start()
3030
} catch(ex: IOException) {
31-
logger.warn("Failed to open {}", this, ex)
31+
logger.warn(ex) { "Failed to open $this" }
3232
}
3333
}
3434
}

src/main/kotlin/sc/gui/view/GameView.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class GameBoard<GameState: IGameState>: View(), ChangeListener<IGameSta
3939
protected val awaitingHumanMove =
4040
gameModel.isHumanTurn.booleanBinding(gameModel.atLatestTurn) {
4141
(gameModel.atLatestTurn.value && gameModel.isHumanTurn.value).also {
42-
logger.trace { "Awaiting Human Turn: $it"}
42+
logger.trace { "Awaiting Human Turn: $it" }
4343
}
4444
}
4545

@@ -116,7 +116,9 @@ abstract class GameBoard<GameState: IGameState>: View(), ChangeListener<IGameSta
116116

117117
protected fun sendHumanMove(move: IMove): Boolean {
118118
if(awaitingHumanMove.value) {
119-
fire(HumanMoveAction(move.also { logger.debug("Human Move: {}", it) }))
119+
fire(HumanMoveAction(move.also {
120+
logger.debug { "Human Move: $it" }
121+
}))
120122
return true
121123
}
122124
return false

src/main/kotlin/sc/gui/view/game/MississippiBoard.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ class MississippiBoard: GameBoard<GameState>() {
136136
}
137137
originalState = state
138138
}
139-
logger.trace("New state for board: ${state.longString()}")
139+
logger.trace { "New state for board: ${state.longString()}" }
140140

141141
state.currentShip.movement += state.currentShip.maxAcc
142142
val pushes = state.getPossiblePushs()
143143
state.currentShip.movement -= state.currentShip.maxAcc
144-
logger.trace("Available Pushes: {}", pushes)
144+
logger.trace { "Available Pushes: $pushes"}
145145

146146
val neighbors = hashMapOf<CubeCoordinates, ArrayList<CubeDirection>>()
147147
state.board.forEachField { cubeCoordinates, field ->
@@ -167,7 +167,7 @@ class MississippiBoard: GameBoard<GameState>() {
167167
state.currentShip.position + it.direction.vector == cubeCoordinates
168168
}
169169
if(push != null) {
170-
logger.debug("Registering Push '{}' for {}", push, piece)
170+
logger.debug { "Registering Push '$push' for $piece" }
171171
piece.glow(.4)
172172
piece.onHover { hover ->
173173
// TODO hover not recognized when stream is on top
@@ -237,7 +237,7 @@ class MississippiBoard: GameBoard<GameState>() {
237237
2 -> "border"
238238
3 -> "border_outer"
239239
else -> {
240-
logger.warn("Piece at $coords has wrong border directions: $dirs")
240+
logger.warn { "Piece at $coords has wrong border directions: $dirs" }
241241
""
242242
}
243243
}
@@ -417,7 +417,7 @@ class MississippiBoard: GameBoard<GameState>() {
417417
}
418418
}
419419

420-
logger.debug("Adding Human Action from keypress {}", action)
420+
logger.debug { "Adding Human Action from keypress $action" }
421421
if(action != null) {
422422
addHumanAction(action)
423423
return true
@@ -539,7 +539,7 @@ class MississippiBoard: GameBoard<GameState>() {
539539

540540
private fun <T: Node> addPiece(node: T, coordinates: CubeCoordinates): T {
541541
if(grid.children.contains(node))
542-
logger.warn("Attempting to add duplicate grid child at $coordinates: $node")
542+
logger.warn { "Attempting to add duplicate grid child at $coordinates: $node" }
543543
else
544544
grid.add(node)
545545
calculatedBlockSize.listenImmediately {

src/main/kotlin/sc/gui/view/game/PenguinsBoard.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class PenguinBoard: View() {
6666
rotate = state.startTeam.index * 180.0
6767
rotationAxis = Rotate.Y_AXIS
6868
// TODO finish pending movements
69-
logger.trace("New state for board: ${state.longString()}")
69+
logger.trace { "New state for board: ${state.longString()}" }
7070

7171
val lastMove = arrayOf(state to state.lastMove, oldState to oldState?.lastMove?.reversed()).maxByOrNull {
7272
it.first?.turn ?: -1
@@ -207,7 +207,7 @@ class PenguinBoard: View() {
207207
event.consume()
208208
}
209209
} else {
210-
logger.error("Invalid State!")
210+
logger.error { "Invalid State!" }
211211
}
212212
}
213213
//image.viewOrder = BOARD_SIZE - coordinates.y.toDouble()
@@ -285,13 +285,13 @@ class PenguinBoard: View() {
285285

286286
private fun humanMove(move: Move) {
287287
if(gameModel.atLatestTurn.value && gameModel.isHumanTurn.value) {
288-
fire(HumanMoveAction(move.also { logger.debug("Human Move: $it") }))
288+
fire(HumanMoveAction(move.also { logger.debug { "Human Move: $it" } }))
289289
}
290290
}
291291

292292
private fun <T: Region> addPiece(node: T, coordinates: Coordinates): T {
293293
if(grid.children.contains(node))
294-
logger.warn("Attempting to add duplicate grid child at $coordinates: $node")
294+
logger.warn { "Attempting to add duplicate grid child at $coordinates: $node" }
295295
else
296296
grid.add(node)
297297
size.listenImmediately {

0 commit comments

Comments
 (0)