From 03be001b2a098b652775eaf5a5a32f2b5fcb8e16 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Thu, 18 Oct 2018 12:15:33 -0600 Subject: [PATCH] Add --logging CLI option (#97) [NC-1675] Ensure that default logging is appropriate * Add CLI flag for logging Signed-off-by: Adrian Sutton --- .../pegasys/pantheon/cli/PantheonCommand.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 3e731a821e..37ac4fd211 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -53,8 +53,8 @@ import java.util.stream.Stream; import com.google.common.net.HostAndPort; import io.vertx.core.Vertx; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; import picocli.CommandLine; import picocli.CommandLine.AbstractParseResultHandler; import picocli.CommandLine.Command; @@ -79,7 +79,6 @@ import picocli.CommandLine.ParameterException; footer = "Pantheon is licensed under the Apache License 2.0" ) public class PantheonCommand implements Runnable { - private static final Logger LOG = LogManager.getLogger(); private static final int DEFAULT_MAX_PEERS = 25; @@ -317,6 +316,12 @@ public class PantheonCommand implements Runnable { ) private final Boolean isDevMode = false; + @Option( + names = {"--logging", "-l"}, + description = "Logging verbosity: OFF, FATAL, WARN, INFO, DEBUG, TRACE, ALL (default: INFO)." + ) + private final Level logLevel = null; + @Option( names = {"--miner-enabled"}, description = "set if node should perform mining (default: ${DEFAULT-VALUE})" @@ -376,10 +381,11 @@ public class PantheonCommand implements Runnable { commandLine.addSubcommand("import-blockchain", importBlockchainSubCommand); commandLine.addSubcommand("export-pub-key", new ExportPublicKeySubCommand()); - commandLine.registerConverter(HostAndPort.class, HostAndPort::fromString); - commandLine.registerConverter(SyncMode.class, SyncMode::fromString); commandLine.registerConverter(Address.class, Address::fromHexString); commandLine.registerConverter(BytesValue.class, BytesValue::fromHexString); + commandLine.registerConverter(HostAndPort.class, HostAndPort::fromString); + commandLine.registerConverter(Level.class, Level::valueOf); + commandLine.registerConverter(SyncMode.class, SyncMode::fromString); commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg))); // Create a handler that will search for a config file option and use it for default values @@ -392,6 +398,12 @@ public class PantheonCommand implements Runnable { @Override public void run() { + // set log level per CLI flags + if (logLevel != null) { + System.out.println("Setting logging level to " + logLevel.name()); + Configurator.setAllLevels("", logLevel); + } + //noinspection ConstantConditions if (isMiningEnabled && coinbase == null) { System.out.println(