From 2ec6fe4c0af82efb60ce495b08256dad12881792 Mon Sep 17 00:00:00 2001 From: JamesHR3 <45565019+JamesHR3@users.noreply.github.com> Date: Tue, 15 Jan 2019 18:54:08 +0000 Subject: [PATCH] [CORDA-2441] Fix Stdout progress renderer to swap out correct appender (#4582) * Fix stdout renderer to swap out correctly named appender. Also fix two compiler warnings * Add clearer exception when console appender cannot be found * Change error displayed when appender not found to warning * Remove type declaration on separate line --- .../tools/shell/utlities/ANSIProgressRenderer.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/shell/src/main/kotlin/net/corda/tools/shell/utlities/ANSIProgressRenderer.kt b/tools/shell/src/main/kotlin/net/corda/tools/shell/utlities/ANSIProgressRenderer.kt index aa520a2e2d..925dd979a7 100644 --- a/tools/shell/src/main/kotlin/net/corda/tools/shell/utlities/ANSIProgressRenderer.kt +++ b/tools/shell/src/main/kotlin/net/corda/tools/shell/utlities/ANSIProgressRenderer.kt @@ -2,6 +2,8 @@ package net.corda.tools.shell.utlities import net.corda.core.internal.Emoji import net.corda.core.messaging.FlowProgressHandle +import net.corda.core.utilities.contextLogger +import net.corda.core.utilities.loggerFor import org.apache.commons.lang.SystemUtils import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.core.LogEvent @@ -14,6 +16,7 @@ import org.fusesource.jansi.Ansi import org.fusesource.jansi.Ansi.Attribute import org.fusesource.jansi.AnsiConsole import org.fusesource.jansi.AnsiOutputStream +import org.slf4j.LoggerFactory import rx.Subscription abstract class ANSIProgressRenderer { @@ -187,7 +190,7 @@ abstract class ANSIProgressRenderer { } } - private fun renderInBold(payload: String, ansi: Ansi): Unit { + private fun renderInBold(payload: String, ansi: Ansi) { with(ansi) { a(Attribute.INTENSITY_BOLD) a(payload) @@ -195,7 +198,7 @@ abstract class ANSIProgressRenderer { } } - private fun renderInFaint(payload: String, ansi: Ansi): Unit { + private fun renderInFaint(payload: String, ansi: Ansi) { with(ansi) { a(Attribute.INTENSITY_FAINT) a(payload) @@ -250,7 +253,11 @@ object StdoutANSIProgressRenderer : ANSIProgressRenderer() { // than doing things the official way with a dedicated plugin, etc, as it avoids mucking around with all // the config XML and lifecycle goop. val manager = LogManager.getContext(false) as LoggerContext - val consoleAppender = manager.configuration.appenders.values.filterIsInstance().single { it.name == "Console-Appender" } + val consoleAppender = manager.configuration.appenders.values.filterIsInstance().singleOrNull { it.name == "Console-Selector" } + if (consoleAppender == null) { + loggerFor().warn("Cannot find console appender - progress tracking may not work as expected") + return + } val scrollingAppender = object : AbstractOutputStreamAppender( consoleAppender.name, consoleAppender.layout, consoleAppender.filter, consoleAppender.ignoreExceptions(), true, consoleAppender.manager) { @@ -295,4 +302,4 @@ object StdoutANSIProgressRenderer : ANSIProgressRenderer() { System.out.print(ansi) System.out.flush() } -} +} \ No newline at end of file