11package io.github.typesafegithub.workflows.jitbindingserver
22
3+ import io.github.oshai.kotlinlogging.KotlinLogging.logger
34import io.github.reactivecircus.cache4k.Cache
45import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
56import io.github.typesafegithub.workflows.actionbindinggenerator.domain.prettyPrint
@@ -10,12 +11,17 @@ import io.github.typesafegithub.workflows.mavenbinding.buildPackageArtifacts
1011import io.github.typesafegithub.workflows.mavenbinding.buildVersionArtifacts
1112import io.github.typesafegithub.workflows.shared.internal.getGithubToken
1213import io.ktor.http.ContentType
14+ import io.ktor.http.HttpHeaders.XRequestId
1315import io.ktor.http.HttpStatusCode
1416import io.ktor.server.application.ApplicationCall
1517import io.ktor.server.application.call
1618import io.ktor.server.application.install
1719import io.ktor.server.engine.embeddedServer
1820import io.ktor.server.netty.Netty
21+ import io.ktor.server.plugins.callid.CallId
22+ import io.ktor.server.plugins.callid.callIdMdc
23+ import io.ktor.server.plugins.callid.generate
24+ import io.ktor.server.plugins.callloging.CallLogging
1925import io.ktor.server.response.respondBytes
2026import io.ktor.server.response.respondText
2127import io.ktor.server.routing.Route
@@ -26,7 +32,23 @@ import io.ktor.server.routing.routing
2632import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing
2733import kotlin.time.Duration.Companion.hours
2834
35+ private val logger =
36+ System
37+ /*
38+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
39+ * !! IMPORTANT: !!
40+ * !! This statement has to always be executed first before **any** other code, !!
41+ * !! or else the property "java.util.logging.manager" may have no effect anymore! !!
42+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
43+ */
44+ .setProperty(" java.util.logging.manager" , org.apache.logging.log4j.jul.LogManager ::class .java.name)
45+ .let { logger { } }
46+
2947fun main () {
48+ Thread .setDefaultUncaughtExceptionHandler { thread, throwable ->
49+ logger.error(throwable) { " Uncaught exception in thread $thread " }
50+ }
51+
3052 val bindingsCache =
3153 Cache
3254 .Builder <ActionCoords , Result <Map <String , Artifact >>>()
@@ -35,6 +57,16 @@ fun main() {
3557 val openTelemetry = buildOpenTelemetryConfig(serviceName = " github-actions-bindings" )
3658
3759 embeddedServer(Netty , port = 8080 ) {
60+ install(CallId ) {
61+ generate(
62+ length = 15 ,
63+ dictionary = " abcdefghijklmnopqrstuvwxyz0123456789" ,
64+ )
65+ replyToHeader(XRequestId )
66+ }
67+ install(CallLogging ) {
68+ callIdMdc(" request-id" )
69+ }
3870 install(KtorServerTracing ) {
3971 setOpenTelemetry(openTelemetry)
4072 }
@@ -155,7 +187,7 @@ private suspend fun ApplicationCall.toBindingArtifacts(
155187 version = version,
156188 path = nameAndPath.drop(1 ).joinToString(" /" ).takeUnless { it.isBlank() },
157189 )
158- println ( " ➡️ Requesting ${actionCoords.prettyPrint} " )
190+ logger.info { " ➡️ Requesting ${actionCoords.prettyPrint} " }
159191 val bindingArtifacts =
160192 if (refresh) {
161193 actionCoords.buildVersionArtifacts().also {
0 commit comments