From f683f50eb5945a8d0ba6819d59945109ef8008c6 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 3 Feb 2016 14:13:04 +0100 Subject: [PATCH] Logging: mention if a log message is a warning or error. --- src/main/kotlin/core/utilities/Logging.kt | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/core/utilities/Logging.kt b/src/main/kotlin/core/utilities/Logging.kt index 5b298db617..e3b451c4b9 100644 --- a/src/main/kotlin/core/utilities/Logging.kt +++ b/src/main/kotlin/core/utilities/Logging.kt @@ -31,27 +31,32 @@ inline fun org.slf4j.Logger.trace(msg: () -> String) { */ class BriefLogFormatter : Formatter() { override fun format(logRecord: LogRecord): String { - val arguments = arrayOfNulls(6) + val arguments = arrayOfNulls(7) arguments[0] = logRecord.threadID + arguments[1] = when (logRecord.level) { + Level.SEVERE -> " **ERROR** " + Level.WARNING -> " (warning) " + else -> "" + } val fullClassName = logRecord.sourceClassName val dollarIndex = fullClassName.indexOf('$') val className = fullClassName.substring(fullClassName.lastIndexOf('.') + 1, if (dollarIndex == -1) fullClassName.length else dollarIndex) - arguments[1] = className - arguments[2] = logRecord.sourceMethodName - arguments[3] = Date(logRecord.millis) - arguments[4] = if (logRecord.parameters != null) MessageFormat.format(logRecord.message, *logRecord.parameters) else logRecord.message + arguments[2] = className + arguments[3] = logRecord.sourceMethodName + arguments[4] = Date(logRecord.millis) + arguments[5] = if (logRecord.parameters != null) MessageFormat.format(logRecord.message, *logRecord.parameters) else logRecord.message if (logRecord.thrown != null) { val result = StringWriter() logRecord.thrown.printStackTrace(PrintWriter(result)) - arguments[5] = result.toString() + arguments[6] = result.toString() } else { - arguments[5] = "" + arguments[6] = "" } return messageFormat.format(arguments) } companion object { - private val messageFormat = MessageFormat("{3,date,HH:mm:ss} {0} {1}.{2}: {4}\n{5}") + private val messageFormat = MessageFormat("{4,date,HH:mm:ss} {0} {1}{2}.{3}: {5}\n{6}") // OpenJDK made a questionable, backwards incompatible change to the Logger implementation. It internally uses // weak references now which means simply fetching the logger and changing its configuration won't work. We must