From 37fe77d5e10d6ee5a9d0aa70d1610bcaf39da571 Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Wed, 16 Nov 2022 10:31:35 -0600 Subject: [PATCH] Add call logging. --- server/src/main/kotlin/Main.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/main/kotlin/Main.kt b/server/src/main/kotlin/Main.kt index 0e6710f..c69bff2 100644 --- a/server/src/main/kotlin/Main.kt +++ b/server/src/main/kotlin/Main.kt @@ -221,14 +221,18 @@ val CALL_START_TIME = AttributeKey("CallStartTime") @Suppress("LongMethod") fun Application.questioner() { intercept(ApplicationCallPipeline.Setup) { - println(Instant.now()) - // intercept before calling routing and mark every incoming call with a TimeMark call.attributes.put(CALL_START_TIME, Instant.now()) } install(CallLogging) { format { call -> - val startTime = call.attributes.getOrNull(CALL_START_TIME)!! - "${call.response.status()}: ${call.request.toLogString()} ${Instant.now().toEpochMilli() - startTime.toEpochMilli()}" + val startTime = call.attributes.getOrNull(CALL_START_TIME) + "${call.response.status()}: ${call.request.toLogString()} ${ + if (startTime != null) { + Instant.now().toEpochMilli() - startTime.toEpochMilli() + } else { + "" + } + }" } } install(ContentNegotiation) {