Skip to content

Commit

Permalink
also print log level when exporting log (#5545)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Mar 25, 2024
1 parent 5df44dd commit e53c279
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ enum class LogLevel {
WARNING,
ERROR
}

fun LogLevel.toChar(): Char = when (this) {
VERBOSE -> 'V'
DEBUG -> 'D'
INFO -> 'I'
WARNING -> 'W'
ERROR -> 'E'
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ data class LogMessage(
}

fun Iterable<LogMessage>.format(tz: TimeZone = TimeZone.currentSystemDefault()): String =
joinToString("\n") {
val timestamp = Instant.fromEpochMilliseconds(it.timestamp)
joinToString("\n") { logMessage ->
val timestamp = Instant.fromEpochMilliseconds(logMessage.timestamp)
.toLocalDateTime(tz)
.toString()

"$timestamp: $it"
val logLevel = logMessage.level.toChar()
"$timestamp: $logLevel $logMessage"
}

0 comments on commit e53c279

Please sign in to comment.