Skip to content

Commit b022a5b

Browse files
authored
Stop logging useless trace to LoggerModel.setup (#2180)
1 parent a072f62 commit b022a5b

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/InstrumentedProcess.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import org.utbot.rd.terminateOnException
3333
import java.io.File
3434

3535
private val logger = KotlinLogging.logger { }
36-
private val rdLogger = UtRdKLogger(logger, "")
3736

3837
private const val UTBOT_INSTRUMENTATION = "utbot-instrumentation"
3938
private const val INSTRUMENTATION_LIB = "lib"
@@ -136,7 +135,7 @@ class InstrumentedProcess private constructor(
136135
logger.trace("rd process started")
137136

138137
val proc = InstrumentedProcess(classLoader, rdProcess)
139-
proc.loggerModel.setup(rdLogger, proc.lifetime)
138+
proc.loggerModel.setup(logger, proc.lifetime)
140139

141140
proc.lifetime.onTermination {
142141
logger.trace { "process is terminating" }

utbot-rd/src/main/kotlin/org/utbot/rd/loggers/UtRdKLogger.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import mu.KLogger
66
/**
77
* Adapter from RD Logger to KLogger
88
*/
9-
class UtRdKLogger(private val realLogger: KLogger, val category: String) : Logger {
9+
class UtRdKLogger(
10+
private val realLogger: KLogger,
11+
val category: String,
12+
private val logTraceOnError: Boolean = true
13+
) : Logger {
1014
val logLevel: LogLevel
1115
get() {
1216
return when {
@@ -24,7 +28,11 @@ class UtRdKLogger(private val realLogger: KLogger, val category: String) : Logge
2428
}
2529

2630
private fun format(level: LogLevel, message: Any?, throwable: Throwable?): String {
27-
val throwableToPrint = if (level < LogLevel.Error) throwable else throwable ?: Exception("No exception was actually thrown, this exception is used purely to log trace")
31+
val throwableToPrint =
32+
if (logTraceOnError && level >= LogLevel.Error)
33+
throwable ?: Exception("No exception was actually thrown, this exception is used purely to log trace")
34+
else
35+
throwable
2836
val rdCategory = if (category.isNotEmpty()) "RdCategory: ${category.substringAfterLast('.').padEnd(25)} | " else ""
2937
return "$rdCategory${message?.toString() ?: ""} ${throwableToPrint?.getThrowableText()?.let { "| $it" } ?: ""}"
3038
}

utbot-rd/src/main/kotlin/org/utbot/rd/loggers/UtRdLogUtil.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ fun overrideDefaultRdLoggerFactoryWithKLogger(logger: KLogger) {
2626
}
2727
}
2828

29-
fun LoggerModel.setup(rdLogger: UtRdKLogger, processLifetime: Lifetime) {
29+
fun LoggerModel.setup(logger: KLogger, processLifetime: Lifetime) {
30+
// we do not log trace on error here because it's a job of clint-side process logger
31+
// server-side process logger can only log trace of where it was set up from which isn't particularly useful
32+
val rdLogger = UtRdKLogger(logger, "", logTraceOnError = false)
3033
// currently we do not specify log level for different categories
3134
// though it is possible with some additional map on categories -> consider performance
3235
// this logLevel is obtained from KotlinLogger

utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/process/SpringAnalyzerProcess.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ private const val SPRING_ANALYZER_JAR_PATH = "lib/$SPRING_ANALYZER_JAR_FILENAME"
3737
private const val UNKNOWN_MODIFICATION_TIME = 0L
3838

3939
private val logger = KotlinLogging.logger {}
40-
private val rdLogger = UtRdKLogger(logger, "")
4140

4241
private var classpathArgs = listOf<String>()
4342

@@ -106,7 +105,7 @@ class SpringAnalyzerProcess private constructor(
106105
}
107106
rdProcess.awaitProcessReady()
108107
val proc = SpringAnalyzerProcess(rdProcess)
109-
proc.loggerModel.setup(rdLogger, proc.lifetime)
108+
proc.loggerModel.setup(logger, proc.lifetime)
110109
return proc
111110
}
112111
}

0 commit comments

Comments
 (0)