From 9648b16ff10567aeb00afc77df217b6a80539394 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 9 Mar 2019 18:26:21 +0000 Subject: [PATCH] CORDA-2725: Set DJVM CLI logging threshold to "TRACE". (#4867) - Configure root logging level programmatically. - Support DEBUG logging level. --- .../kotlin/net/corda/djvm/tools/cli/CommandBase.kt | 14 ++++++++++++++ djvm/cli/src/main/resources/log4j2.xml | 2 +- .../kotlin/net/corda/djvm/messages/Severity.kt | 7 ++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt b/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt index d4a3c4afb8..13c337acb3 100644 --- a/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt +++ b/djvm/cli/src/main/kotlin/net/corda/djvm/tools/cli/CommandBase.kt @@ -8,6 +8,8 @@ import net.corda.djvm.references.ClassReference import net.corda.djvm.references.EntityReference import net.corda.djvm.references.MemberReference import net.corda.djvm.rewiring.SandboxClassLoadingException +import org.apache.logging.log4j.Level +import org.apache.logging.log4j.core.config.Configurator import picocli.CommandLine import picocli.CommandLine.Help.Ansi import picocli.CommandLine.Option @@ -102,6 +104,7 @@ abstract class CommandBase : Callable { printError("Error: Cannot set verbose and quiet modes at the same time") return false } + configureLogging() return try { handleCommand() } catch (exception: Throwable) { @@ -110,6 +113,17 @@ abstract class CommandBase : Callable { } } + private fun configureLogging() { + val logLevel = when(level) { + Severity.ERROR -> Level.ERROR + Severity.WARNING -> Level.WARN + Severity.INFORMATIONAL -> Level.INFO + Severity.DEBUG -> Level.DEBUG + Severity.TRACE -> Level.TRACE + } + Configurator.setRootLevel(logLevel) + } + protected fun printException(exception: Throwable) = when (exception) { is SandboxClassLoadingException -> { printMessages(exception.messages, exception.classOrigins) diff --git a/djvm/cli/src/main/resources/log4j2.xml b/djvm/cli/src/main/resources/log4j2.xml index 93e84b6252..648a657dc3 100644 --- a/djvm/cli/src/main/resources/log4j2.xml +++ b/djvm/cli/src/main/resources/log4j2.xml @@ -1,7 +1,7 @@ - + diff --git a/djvm/src/main/kotlin/net/corda/djvm/messages/Severity.kt b/djvm/src/main/kotlin/net/corda/djvm/messages/Severity.kt index 1d067b950b..9b04b920ef 100644 --- a/djvm/src/main/kotlin/net/corda/djvm/messages/Severity.kt +++ b/djvm/src/main/kotlin/net/corda/djvm/messages/Severity.kt @@ -12,7 +12,12 @@ enum class Severity(val shortName: String, val precedence: Int, val color: Strin /** * Trace message. */ - TRACE("TRACE", 3, null), + TRACE("TRACE", 4, null), + + /** + * Debug message. + */ + DEBUG("DEBUG", 3, null), /** * Informational message.