Add --logging CLI option (#97)

[NC-1675] Ensure that default logging is appropriate

* Add CLI flag for logging
Danno Ferrin 6 years ago committed by GitHub
parent 840780bffc
commit 60890e0ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      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 com.google.common.net.HostAndPort;
import io.vertx.core.Vertx; import io.vertx.core.Vertx;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.config.Configurator;
import picocli.CommandLine; import picocli.CommandLine;
import picocli.CommandLine.AbstractParseResultHandler; import picocli.CommandLine.AbstractParseResultHandler;
import picocli.CommandLine.Command; import picocli.CommandLine.Command;
@ -79,7 +79,6 @@ import picocli.CommandLine.ParameterException;
footer = "Pantheon is licensed under the Apache License 2.0" footer = "Pantheon is licensed under the Apache License 2.0"
) )
public class PantheonCommand implements Runnable { public class PantheonCommand implements Runnable {
private static final Logger LOG = LogManager.getLogger();
private static final int DEFAULT_MAX_PEERS = 25; private static final int DEFAULT_MAX_PEERS = 25;
@ -317,6 +316,12 @@ public class PantheonCommand implements Runnable {
) )
private final Boolean isDevMode = false; 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( @Option(
names = {"--miner-enabled"}, names = {"--miner-enabled"},
description = "set if node should perform mining (default: ${DEFAULT-VALUE})" 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("import-blockchain", importBlockchainSubCommand);
commandLine.addSubcommand("export-pub-key", new ExportPublicKeySubCommand()); 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(Address.class, Address::fromHexString);
commandLine.registerConverter(BytesValue.class, BytesValue::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))); 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 // 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 @Override
public void run() { 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 //noinspection ConstantConditions
if (isMiningEnabled && coinbase == null) { if (isMiningEnabled && coinbase == null) {
System.out.println( System.out.println(

Loading…
Cancel
Save