Skip to content

Commit

Permalink
Allow tuning the logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
vegarsti committed Jul 2, 2024
1 parent 805a510 commit f34feb8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_LEVEL=debug ./indexer
```

Or run it directly with `go run`:
Expand All @@ -43,6 +43,9 @@ docker run duneanalytics/node-indexer --help

Also, we mention some of the options here:

### Log level
Use `LOG_LEVEL=debug` (`--log-level`) to emit more logs than the default `info` level.

### 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.
Expand Down
15 changes: 14 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-level" env:"LOG_LEVEL" description:"Log level" choice:"info" choice:"debug" choice:"warn" choice:"error" default:"info"` // nolint:lll
}

func (c Config) HasError() error {
Expand Down

0 comments on commit f34feb8

Please sign in to comment.