-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ethpandaops/feat/go-eth2-log-level
fix: Pass through log level to go-eth2-api
- Loading branch information
Showing
5 changed files
with
115 additions
and
7 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,43 @@ | ||
package beacon | ||
|
||
import ( | ||
"github.com/rs/zerolog" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (n *node) GetZeroLogLevel() zerolog.Level { | ||
if n.log == nil { | ||
return zerolog.NoLevel | ||
} | ||
|
||
var logLevel logrus.Level | ||
|
||
// Handle both Logger and Entry types | ||
switch v := n.log.(type) { | ||
case *logrus.Logger: | ||
logLevel = v.GetLevel() | ||
case *logrus.Entry: | ||
logLevel = v.Logger.GetLevel() | ||
default: | ||
return zerolog.NoLevel | ||
} | ||
|
||
zerologLevel := zerolog.NoLevel | ||
|
||
switch logLevel { | ||
case logrus.DebugLevel: | ||
zerologLevel = zerolog.DebugLevel | ||
case logrus.InfoLevel: | ||
zerologLevel = zerolog.InfoLevel | ||
case logrus.WarnLevel: | ||
zerologLevel = zerolog.WarnLevel | ||
case logrus.ErrorLevel: | ||
zerologLevel = zerolog.ErrorLevel | ||
case logrus.FatalLevel: | ||
zerologLevel = zerolog.FatalLevel | ||
case logrus.PanicLevel: | ||
zerologLevel = zerolog.PanicLevel | ||
} | ||
|
||
return zerologLevel | ||
} |
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,61 @@ | ||
package beacon_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethpandaops/beacon/pkg/beacon" | ||
"github.com/rs/zerolog" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetZeroLogLevel(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
logLevel logrus.Level | ||
want zerolog.Level | ||
}{ | ||
{ | ||
name: "debug level", | ||
logLevel: logrus.DebugLevel, | ||
want: zerolog.DebugLevel, | ||
}, | ||
{ | ||
name: "info level", | ||
logLevel: logrus.InfoLevel, | ||
want: zerolog.InfoLevel, | ||
}, | ||
{ | ||
name: "warn level", | ||
logLevel: logrus.WarnLevel, | ||
want: zerolog.WarnLevel, | ||
}, | ||
{ | ||
name: "error level", | ||
logLevel: logrus.ErrorLevel, | ||
want: zerolog.ErrorLevel, | ||
}, | ||
{ | ||
name: "fatal level", | ||
logLevel: logrus.FatalLevel, | ||
want: zerolog.FatalLevel, | ||
}, | ||
{ | ||
name: "panic level", | ||
logLevel: logrus.PanicLevel, | ||
want: zerolog.PanicLevel, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
logger := logrus.New() | ||
logger.SetLevel(tt.logLevel) | ||
|
||
node := beacon.NewNode(logger, &beacon.Config{}, "", beacon.Options{}) | ||
got := node.GetZeroLogLevel() | ||
|
||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
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