Skip to content

Commit

Permalink
Allow custom levelers for grpc interceptors
Browse files Browse the repository at this point in the history
The logging interceptors can now be provided with options that enable
custom logging levels for log messages and payloads.

Introduced Payload and Disabled logging levels. The Payload level will
be the default level used to log grpc message contents. It should be
extremely rare that this information is needed. The Disabled level can
be used programmatically to completely disable a logger.

The orderer main is updated to exploit the leveler option to disable any
grpc logging for Step function of the orderer.Cluster service.

FAB-12952 #done
FAB-12933 #done

Change-Id: Id1e39762b2cbd3a317a0710d0b229559dd7807a3
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Nov 27, 2018
1 parent 17e239e commit 6922e14
Show file tree
Hide file tree
Showing 8 changed files with 456 additions and 63 deletions.
15 changes: 14 additions & 1 deletion common/flogging/levels.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ package flogging

import (
"fmt"
"math"

"go.uber.org/zap/zapcore"
)

const (
// DisabledLevel represents a disabled log level. Logs at this level should
// never be emitted.
DisabledLevel = zapcore.Level(math.MinInt8)

// PayloadLevel is used to log the extremely detailed message level debug
// information.
PayloadLevel = zapcore.Level(zapcore.DebugLevel - 1)
)

// NameToLevel converts a level name to a zapcore.Level. If the level name is
// unknown, zapcore.InfoLevel is returned.
func NameToLevel(level string) zapcore.Level {
Expand All @@ -24,6 +35,8 @@ func NameToLevel(level string) zapcore.Level {

func nameToLevel(level string) (zapcore.Level, error) {
switch level {
case "PAYLOAD", "payload":
return PayloadLevel, nil
case "DEBUG", "debug":
return zapcore.DebugLevel, nil
case "INFO", "info":
Expand All @@ -45,7 +58,7 @@ func nameToLevel(level string) (zapcore.Level, error) {
return zapcore.ErrorLevel, nil // future

default:
return zapcore.Level(-99), fmt.Errorf("invalid log level: %s", level)
return DisabledLevel, fmt.Errorf("invalid log level: %s", level)
}
}

Expand Down
3 changes: 3 additions & 0 deletions common/flogging/levels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestNameToLevel(t *testing.T) {
names []string
level zapcore.Level
}{
{names: []string{"PAYLOAD", "payload"}, level: flogging.PayloadLevel},
{names: []string{"DEBUG", "debug"}, level: zapcore.DebugLevel},
{names: []string{"INFO", "info"}, level: zapcore.InfoLevel},
{names: []string{"WARNING", "warning", "WARN", "warn"}, level: zapcore.WarnLevel},
Expand All @@ -42,6 +43,7 @@ func TestNameToLevel(t *testing.T) {

func TestIsValidLevel(t *testing.T) {
validNames := []string{
"PAYLOAD", "payload",
"DEBUG", "debug",
"INFO", "info",
"WARNING", "warning",
Expand All @@ -62,6 +64,7 @@ func TestIsValidLevel(t *testing.T) {
invalidNames := []string{
"george", "bob",
"warnings", "inf",
"DISABLED", "disabled", // can only be used programmatically
}
for _, name := range invalidNames {
t.Run(name, func(t *testing.T) {
Expand Down
38 changes: 31 additions & 7 deletions common/grpclogging/fakes/echo_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 112 additions & 0 deletions common/grpclogging/fakes/leveler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6922e14

Please sign in to comment.