diff --git a/README.md b/README.md index c07e1f8..cae9bb1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Build the binary for your OS: ```bash $ make build -$ BLOCKCHAIN_NAME='foo' RPC_NODE_URL='http://localhost:8545' DUNE_API_KEY='your-key-here' ./indexer +$ BLOCKCHAIN_NAME='foo' RPC_NODE_URL='http://localhost:8545' DUNE_API_KEY='your-key-here' LOG=debug ./indexer ``` Or run it directly with `go run`: @@ -43,6 +43,9 @@ docker run duneanalytics/node-indexer --help Also, we mention some of the options here: +### Log level +Use `LOG=debug` (`--log`) to emit more logs than the default `info` level. To emit less logs, use `warn`, or `error` (least). + ### Tuning RPC concurrency The flag `--rpc-concurrency` (environment variable `RPC_CONCURRENCY`) specifies the number of threads (goroutines) to run concurrently to perform RPC node requests. Default is 25. diff --git a/cmd/main.go b/cmd/main.go index 3416ebb..b1c7e86 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -31,7 +31,20 @@ func main() { if err != nil { stdlog.Fatal(err) } - logger := slog.New(slog.NewTextHandler(os.Stderr, nil)) + logOptions := &slog.HandlerOptions{} + switch cfg.LogLevel { + case "debug": + logOptions.Level = slog.LevelDebug + case "info": + logOptions.Level = slog.LevelInfo + case "warn": + logOptions.Level = slog.LevelWarn + case "error": + logOptions.Level = slog.LevelError + default: + stdlog.Fatalf("unsupported log level: '%s'", cfg.LogLevel) + } + logger := slog.New(slog.NewTextHandler(os.Stderr, logOptions)) slog.SetDefault(logger) duneClient, err := duneapi.New(logger, duneapi.Config{ diff --git a/config/config.go b/config/config.go index 32fe0cb..8259943 100644 --- a/config/config.go +++ b/config/config.go @@ -52,6 +52,7 @@ type Config struct { RPCStack models.EVMStack `long:"rpc-stack" env:"RPC_STACK" description:"Stack for the RPC client" default:"opstack"` // nolint:lll RPCConcurrency int `long:"rpc-concurrency" env:"RPC_CONCURRENCY" description:"Number of concurrent requests to the RPC node" default:"25"` // nolint:lll BlockSubmitInterval time.Duration `long:"block-submit-interval" env:"BLOCK_SUBMIT_INTERVAL" description:"Interval at which to submit batched blocks to Dune" default:"500ms"` // nolint:lll + LogLevel string `long:"log" env:"LOG" description:"Log level" choice:"info" choice:"debug" choice:"warn" choice:"error" default:"info"` // nolint:lll } func (c Config) HasError() error {