Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Add call logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Nov 16, 2022
1 parent 84db7ca commit 37fe77d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,18 @@ val CALL_START_TIME = AttributeKey<Instant>("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) {
Expand Down

0 comments on commit 37fe77d

Please sign in to comment.