Skip to content

Commit

Permalink
Merge pull request #12406 from tangcong/silence-stream-log
Browse files Browse the repository at this point in the history
embed: only log stream error with debug level
  • Loading branch information
gyuho committed Oct 20, 2020
2 parents d5363e3 + 27d308e commit ae962f7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions embed/config_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package embed
import (
"crypto/tls"
"fmt"
"io/ioutil"
"os"
"sync"

"go.etcd.io/etcd/pkg/v3/logutil"
Expand Down Expand Up @@ -107,10 +109,14 @@ func (cfg *Config) setupLogging() error {
grpcLogOnce.Do(func() {
// debug true, enable info, warning, error
// debug false, only discard info
var gl grpclog.LoggerV2
gl, err = logutil.NewGRPCLoggerV2(copied)
if err == nil {
grpclog.SetLoggerV2(gl)
if cfg.LogLevel == "debug" {
var gl grpclog.LoggerV2
gl, err = logutil.NewGRPCLoggerV2(copied)
if err == nil {
grpclog.SetLoggerV2(gl)
}
} else {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))
}
})
return nil
Expand Down Expand Up @@ -154,7 +160,11 @@ func (cfg *Config) setupLogging() error {
c.loggerWriteSyncer = syncer

grpcLogOnce.Do(func() {
grpclog.SetLoggerV2(logutil.NewGRPCLoggerV2FromZapCore(cr, syncer))
if cfg.LogLevel == "debug" {
grpclog.SetLoggerV2(logutil.NewGRPCLoggerV2FromZapCore(cr, syncer))
} else {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))
}
})
return nil
}
Expand Down

0 comments on commit ae962f7

Please sign in to comment.