-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change log-level cli opt to take a string
The log-level cli opt on all executables built by this project now takes a string instead of an integer, and the strings are the typical CRIT, ERROR, WARN, INFO, DEBUG, TRACE. Additionally it accepts the old geth numeric log levels as an undocumented feature to avoid the need for anyone already using them to migrate their config. The introduction of slog as geth's logger changed the numeric constants used for the typical levels, so we make this change to avoid requiring any config changes and also to give clearer options going forward.
- Loading branch information
1 parent
ce3cc19
commit 7b9691a
Showing
8 changed files
with
74 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2024, Offchain Labs, Inc. | ||
// For license information, see https://github.com/nitro/blob/master/LICENSE | ||
|
||
package genericconf | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
"golang.org/x/exp/slog" | ||
) | ||
|
||
func ToSlogLevel(str string) (slog.Level, error) { | ||
switch strings.ToLower(str) { | ||
case "trace": | ||
return log.LevelTrace, nil | ||
case "debug": | ||
return log.LevelDebug, nil | ||
case "info": | ||
return log.LevelInfo, nil | ||
case "warn": | ||
return log.LevelWarn, nil | ||
case "error": | ||
return log.LevelError, nil | ||
case "crit": | ||
return log.LevelCrit, nil | ||
default: | ||
legacyLevel, err := strconv.Atoi(str) | ||
if err != nil { | ||
// Leave legacy geth numeric log levels undocumented, but if anyone happens | ||
// to be using them, it will work. | ||
return log.LevelTrace, errors.New("invalid log-level") | ||
} | ||
return log.FromLegacyLevel(legacyLevel), nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters