Skip to content

Commit

Permalink
fix legacy lvls (#1175)
Browse files Browse the repository at this point in the history
* fix legacy lvls

* fix simulator logger
  • Loading branch information
ceyonur authored May 15, 2024
1 parent 1c58950 commit ce0097d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
9 changes: 5 additions & 4 deletions cmd/simulator/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/ava-labs/subnet-evm/cmd/simulator/config"
"github.com/ava-labs/subnet-evm/cmd/simulator/load"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/log"
"github.com/ava-labs/subnet-evm/log"
gethlog "github.com/ethereum/go-ethereum/log"
"github.com/spf13/pflag"
)

Expand All @@ -38,12 +38,13 @@ func main() {
os.Exit(0)
}

logLevel, err := utils.LvlFromString(v.GetString(config.LogLevelKey))
logLevel, err := log.LvlFromString(v.GetString(config.LogLevelKey))
if err != nil {
fmt.Printf("couldn't parse log level: %s\n", err)
os.Exit(1)
}
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, logLevel, true)))
gethLogger := gethlog.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, logLevel, true))
gethlog.SetDefault(gethLogger)

config, err := config.BuildConfig(v)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package log

import (
"context"
"fmt"
"math"
"os"
"runtime"
"strings"
"time"

"golang.org/x/exp/slog"
Expand Down Expand Up @@ -36,6 +38,27 @@ const (
LvlDebug = LevelDebug
)

// LvlFromString returns the appropriate Lvl from a string name.
// Useful for parsing command line args and configuration files.
func LvlFromString(lvlString string) (slog.Level, error) {
switch strings.ToLower(lvlString) {
case "trace", "trce":
return LevelTrace, nil
case "debug", "dbug":
return LevelDebug, nil
case "info":
return LevelInfo, nil
case "warn":
return LevelWarn, nil
case "error", "eror":
return LevelError, nil
case "crit":
return LevelCrit, nil
default:
return LvlDebug, fmt.Errorf("unknown level: %v", lvlString)
}
}

// convert from old Geth verbosity level constants
// to levels defined by slog
func FromLegacyLevel(lvl int) slog.Level {
Expand Down
3 changes: 1 addition & 2 deletions plugin/evm/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/ava-labs/subnet-evm/log"
"github.com/ava-labs/subnet-evm/utils"
gethlog "github.com/ethereum/go-ethereum/log"
"golang.org/x/exp/slog"
)
Expand Down Expand Up @@ -62,7 +61,7 @@ func InitLogger(alias string, level string, jsonFormat bool, writer io.Writer) (
// SetLogLevel sets the log level of initialized log handler.
func (s *SubnetEVMLogger) SetLogLevel(level string) error {
// Set log level
logLevel, err := utils.LvlFromString(level)
logLevel, err := log.LvlFromString(level)
if err != nil {
return err
}
Expand Down
12 changes: 0 additions & 12 deletions utils/log.go

This file was deleted.

0 comments on commit ce0097d

Please sign in to comment.