Skip to content

Commit 2c88925

Browse files
fix: Improve startup logging
1 parent cd73b8e commit 2c88925

File tree

5 files changed

+52
-53
lines changed

5 files changed

+52
-53
lines changed

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ object Versions {
55
const val APACHE_CURATORS = "5.9.0"
66
const val APACHE_TIKA = "3.2.3"
77
const val ARWEAVE4S = "0.21.0"
8-
const val AWS = "2.34.3"
8+
const val AWS = "2.34.5"
99
const val AYZA = "10.0.0"
1010
const val BOUNCY_CASTLE = "1.70"
1111
const val CAFFEINE = "3.2.2"
1212
const val CBOR = "0.4.1-NEWM"
1313
const val CLOUDINARY = "1.39.0"
1414
const val COROUTINES = "1.10.2"
1515
const val EXPOSED = "0.61.0"
16-
const val FLYWAYDB = "11.13.1"
16+
const val FLYWAYDB = "11.13.2"
1717
const val GOOGLE_TRUTH = "1.4.5"
1818
const val GRPC = "1.75.0"
1919
const val GRPC_KOTLIN = "1.5.0"

newm-chain/src/main/kotlin/io/newm/chain/Application.kt

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import io.newm.chain.di.installDependencyInjection
99
import io.newm.chain.grpc.GrpcConfig
1010
import io.newm.chain.grpc.JwtAuthorizationServerInterceptor
1111
import io.newm.chain.logging.initializeSentry
12+
import io.newm.shared.application.printJvmCommandLine
1213
import io.newm.shared.daemon.initializeDaemons
13-
import java.lang.management.ManagementFactory
14-
import java.util.jar.JarFile
1514
import kotlin.system.exitProcess
1615
import kotlinx.coroutines.delay
1716
import kotlinx.coroutines.launch
@@ -22,36 +21,12 @@ private var createJwtUser: String = ""
2221

2322
private val log by lazy { KotlinLogging.logger {} }
2423

25-
private fun printJvmCommandLine() {
26-
val runtimeMxBean = ManagementFactory.getRuntimeMXBean()
27-
val jvmArgs = runtimeMxBean.inputArguments.joinToString(" ")
28-
val jarPath = Application::class.java.protectionDomain.codeSource.location.path
29-
val jarFile = JarFile(jarPath)
30-
val manifest = jarFile.manifest
31-
val buildTime = manifest.mainAttributes.getValue("Build-Time")
32-
33-
log.info { "******************************************************" }
34-
log.info { "JVM command line arguments: $jvmArgs" }
35-
log.info { "Max Heap Size: ${Runtime.getRuntime().maxMemory() / (1024 * 1024)} MB" }
36-
log.info { "Build Time: $buildTime" }
37-
log.info { "******************************************************" }
38-
}
39-
4024
fun main(args: Array<String>) {
41-
// Set root log level to INFO
4225
val root: Logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger
4326
when {
44-
"DEBUG" in args -> {
45-
root.level = Level.DEBUG
46-
}
47-
48-
"TRACE" in args -> {
49-
root.level = Level.TRACE
50-
}
51-
52-
else -> {
53-
root.level = Level.INFO
54-
}
27+
"DEBUG" in args -> root.level = Level.DEBUG
28+
"TRACE" in args -> root.level = Level.TRACE
29+
else -> root.level = Level.INFO
5530
}
5631
// Regular SQL logging
5732
(exposedLogger as Logger).level = Level.INFO
@@ -62,9 +37,15 @@ fun main(args: Array<String>) {
6237
createJwtUser = args[args.indexOf("JWT") + 1]
6338
}
6439

65-
printJvmCommandLine()
66-
io.newm.ktor.server.grpc.EngineMain
67-
.main(args, GrpcConfig.init)
40+
printJvmCommandLine(log)
41+
42+
try {
43+
io.newm.ktor.server.grpc.EngineMain
44+
.main(args, GrpcConfig.init)
45+
} catch (e: Exception) {
46+
log.error(e) { "Failed to start gRPC Ktor Application!" }
47+
throw e
48+
}
6849
}
6950

7051
@Suppress("unused")

newm-server/src/main/kotlin/io/newm/server/Application.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,13 @@ import io.newm.server.logging.initializeSentry
3232
import io.newm.server.logging.installCallLogging
3333
import io.newm.server.staticcontent.createStaticContentRoutes
3434
import io.newm.server.statuspages.installStatusPages
35+
import io.newm.shared.application.printJvmCommandLine
3536
import io.newm.shared.daemon.initializeDaemons
36-
import java.lang.management.ManagementFactory
37-
import java.util.jar.JarFile
3837

3938
private val log by lazy { KotlinLogging.logger {} }
4039

41-
private fun printJvmCommandLine() {
42-
val runtimeMxBean = ManagementFactory.getRuntimeMXBean()
43-
val jvmArgs = runtimeMxBean.inputArguments.joinToString(" ")
44-
val jarPath = Application::class.java.protectionDomain.codeSource.location.path
45-
val jarFile = JarFile(jarPath)
46-
val manifest = jarFile.manifest
47-
val buildTime = manifest.mainAttributes.getValue("Build-Time")
48-
49-
log.info { "******************************************************" }
50-
log.info { "JVM command line arguments: $jvmArgs" }
51-
log.info { "Max Heap Size: ${Runtime.getRuntime().maxMemory() / (1024 * 1024)} MB" }
52-
log.info { "Build Time: $buildTime" }
53-
log.info { "******************************************************" }
54-
}
55-
5640
fun main(args: Array<String>) {
57-
printJvmCommandLine()
41+
printJvmCommandLine(log)
5842
try {
5943
io.ktor.server.cio.EngineMain
6044
.main(args)

newm-server/src/main/kotlin/io/newm/server/features/user/model/User.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ data class User(
2222
val firstName: String? = null,
2323
val lastName: String? = null,
2424
// nickname should be accessed through stageOrFullName
25-
@VisibleForTesting
25+
@param:VisibleForTesting
26+
@property:VisibleForTesting
2627
val nickname: String? = null,
2728
val pictureUrl: String? = null,
2829
val bannerUrl: String? = null,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.newm.shared.application
2+
3+
import io.github.oshai.kotlinlogging.KLogger
4+
import io.github.oshai.kotlinlogging.KotlinLogging
5+
import io.ktor.server.application.Application
6+
import java.lang.management.ManagementFactory
7+
import java.util.jar.JarFile
8+
9+
/**
10+
* Logs common JVM / build information at application startup.
11+
* Can be reused by any service (HTTP, gRPC, etc.) for consistent startup diagnostics.
12+
*
13+
* @param log Optional logger. If not provided a default logger will be used.
14+
*/
15+
fun printJvmCommandLine(log: KLogger = KotlinLogging.logger {}) {
16+
try {
17+
val runtimeMxBean = ManagementFactory.getRuntimeMXBean()
18+
val jvmArgs = runtimeMxBean.inputArguments.joinToString(" ")
19+
val jarPath = Application::class.java.protectionDomain.codeSource.location.path
20+
val buildTime = JarFile(jarPath).use { jarFile ->
21+
jarFile.manifest.mainAttributes.getValue("Build-Time")
22+
}
23+
24+
log.info { "******************************************************" }
25+
log.info { "JVM command line arguments: $jvmArgs" }
26+
log.info { "Max Heap Size: ${Runtime.getRuntime().maxMemory() / (1024 * 1024)} MB" }
27+
log.info { "Build Time: $buildTime" }
28+
log.info { "******************************************************" }
29+
} catch (e: Exception) {
30+
// Fail-safe: never let a logging helper prevent startup
31+
log.warn(e) { "Unable to log JVM startup information." }
32+
}
33+
}

0 commit comments

Comments
 (0)