mirror of
https://github.com/corda/corda.git
synced 2025-01-29 15:43:55 +00:00
Logging: mention if a log message is a warning or error.
This commit is contained in:
parent
af116f6990
commit
f683f50eb5
@ -31,27 +31,32 @@ inline fun org.slf4j.Logger.trace(msg: () -> String) {
|
||||
*/
|
||||
class BriefLogFormatter : Formatter() {
|
||||
override fun format(logRecord: LogRecord): String {
|
||||
val arguments = arrayOfNulls<Any>(6)
|
||||
val arguments = arrayOfNulls<Any>(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
|
||||
|
Loading…
x
Reference in New Issue
Block a user