Skip to content

Commit

Permalink
feat: config log level by option
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod authored and GrapeBaBa committed Dec 6, 2023
1 parent e25eeb0 commit 68e7c92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
13 changes: 12 additions & 1 deletion hildr-node/src/main/java/io/optimism/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.optimism.cli;

import ch.qos.logback.classic.Level;
import io.micrometer.tracing.Tracer;
import io.optimism.cli.typeconverter.LogLevelConverter;
import io.optimism.cli.typeconverter.SyncModeConverter;
import io.optimism.common.HildrServiceExecutionException;
import io.optimism.config.Config;
Expand Down Expand Up @@ -112,13 +114,22 @@ public class Cli implements Runnable {
Integer metricsPort;

@Option(names = "--devnet", description = "Dev net flag")
private Boolean devnet;
Boolean devnet;

@Option(
names = "--log-level",
defaultValue = "DEBUG",
converter = LogLevelConverter.class,
description = "Log level")
Level logLevel;

/** the Cli constructor. */
public Cli() {}

@Override
public void run() {
var logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.setLevel(logLevel);
TracerTaskWrapper.setTracerSupplier(Logging.INSTANCE::getTracer);
if (Boolean.TRUE.equals(metricsEnable)) {
var metricsPort = this.metricsPort;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.optimism.cli.typeconverter;

import ch.qos.logback.classic.Level;
import picocli.CommandLine;

/**
* the Log Level converter, used for picocli parse args.
*
* @author thinkAfCod
* @since 0.2.0
*/
public class LogLevelConverter implements CommandLine.ITypeConverter<ch.qos.logback.classic.Level> {

/** the LogLevelConverter constructor. */
public LogLevelConverter() {}

@Override
public Level convert(String value) throws Exception {
return Level.valueOf(value);
}
}

0 comments on commit 68e7c92

Please sign in to comment.