Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79c2ce7

Browse files
committed
Kotlin: Add tags to log messages (WARN, INFO, etc)
Makes it easier to see what's going on
1 parent 84c7b23 commit 79c2ce7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • java/kotlin-extractor/src/main/kotlin/utils

java/kotlin-extractor/src/main/kotlin/utils/Logger.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,29 @@ open class LoggerBase(val logCounter: LogCounter) {
9090
val locationId = mkLocationId()
9191
tw.writeDiagnostics(StarLabel(), "CodeQL Kotlin extractor", severity.sev, "", msg, "$ts $fullMsg", locationId)
9292
val locStr = if (locationString == null) "" else "At " + locationString + ": "
93-
logStream.write("$ts Diagnostic($diagnosticLocStr): $locStr$fullMsg")
93+
val kind = if (severity <= Severity.WarnHigh) "WARN" else "ERROR"
94+
logStream.write("$ts [$kind] Diagnostic($diagnosticLocStr): $locStr$fullMsg")
9495
}
9596

9697
fun trace(tw: TrapWriter, msg: String) {
97-
debug(tw, msg)
98+
if (verbosity >= 4) {
99+
val fullMsg = "${timestamp()} [TRACE] $msg"
100+
tw.writeComment(fullMsg)
101+
logStream.write(fullMsg + "\n")
102+
}
98103
}
99104

100105
fun debug(tw: TrapWriter, msg: String) {
101106
if (verbosity >= 4) {
102-
val fullMsg = "${timestamp()} $msg"
107+
val fullMsg = "${timestamp()} [DEBUG] $msg"
103108
tw.writeComment(fullMsg)
104109
logStream.write(fullMsg + "\n")
105110
}
106111
}
107112

108113
fun info(tw: TrapWriter, msg: String) {
109114
if (verbosity >= 3) {
110-
val fullMsg = "${timestamp()} $msg"
115+
val fullMsg = "${timestamp()} [INFO] $msg"
111116
tw.writeComment(fullMsg)
112117
logStream.write(fullMsg + "\n")
113118
}

0 commit comments

Comments
 (0)