Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

Commit 7095bdc

Browse files
authored
Allow tuning the logging level (#55)
1 parent 805a510 commit 7095bdc

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Build the binary for your OS:
2727
```bash
2828
$ make build
2929

30-
$ BLOCKCHAIN_NAME='foo' RPC_NODE_URL='http://localhost:8545' DUNE_API_KEY='your-key-here' ./indexer
30+
$ BLOCKCHAIN_NAME='foo' RPC_NODE_URL='http://localhost:8545' DUNE_API_KEY='your-key-here' LOG=debug ./indexer
3131
```
3232

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

4444
Also, we mention some of the options here:
4545

46+
### Log level
47+
Use `LOG=debug` (`--log`) to emit more logs than the default `info` level. To emit less logs, use `warn`, or `error` (least).
48+
4649
### Tuning RPC concurrency
4750
The flag `--rpc-concurrency` (environment variable `RPC_CONCURRENCY`) specifies the number of threads (goroutines)
4851
to run concurrently to perform RPC node requests. Default is 25.

cmd/main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ func main() {
3131
if err != nil {
3232
stdlog.Fatal(err)
3333
}
34-
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
34+
logOptions := &slog.HandlerOptions{}
35+
switch cfg.LogLevel {
36+
case "debug":
37+
logOptions.Level = slog.LevelDebug
38+
case "info":
39+
logOptions.Level = slog.LevelInfo
40+
case "warn":
41+
logOptions.Level = slog.LevelWarn
42+
case "error":
43+
logOptions.Level = slog.LevelError
44+
default:
45+
stdlog.Fatalf("unsupported log level: '%s'", cfg.LogLevel)
46+
}
47+
logger := slog.New(slog.NewTextHandler(os.Stderr, logOptions))
3548
slog.SetDefault(logger)
3649

3750
duneClient, err := duneapi.New(logger, duneapi.Config{

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Config struct {
5252
RPCStack models.EVMStack `long:"rpc-stack" env:"RPC_STACK" description:"Stack for the RPC client" default:"opstack"` // nolint:lll
5353
RPCConcurrency int `long:"rpc-concurrency" env:"RPC_CONCURRENCY" description:"Number of concurrent requests to the RPC node" default:"25"` // nolint:lll
5454
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
55+
LogLevel string `long:"log" env:"LOG" description:"Log level" choice:"info" choice:"debug" choice:"warn" choice:"error" default:"info"` // nolint:lll
5556
}
5657

5758
func (c Config) HasError() error {

0 commit comments

Comments
 (0)