From f2373a5575a413fce657e938c11630027052604a Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 19 Aug 2020 12:25:38 -0400 Subject: [PATCH] logging: move init of grpclog This line initializes global state. Moving it out of the constructor and closer to where logging is setup helps keep related things together. --- agent/agent.go | 4 ---- agent/setup.go | 2 ++ logging/grpc.go | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index bc5af6abcb..63ad93564b 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -23,7 +23,6 @@ import ( "github.com/hashicorp/go-memdb" "google.golang.org/grpc" - "google.golang.org/grpc/grpclog" "github.com/armon/go-metrics" "github.com/hashicorp/consul/acl" @@ -354,9 +353,6 @@ func New(bd BaseDeps) (*Agent, error) { autoConf: bd.AutoConfig, } - // TODO: set globals somewhere else, not Agent.New - grpclog.SetLoggerV2(logging.NewGRPCLogger(bd.RuntimeConfig.LogLevel, bd.Logger)) - a.serviceManager = NewServiceManager(&a) // TODO: do this somewhere else, maybe move to newBaseDeps diff --git a/agent/setup.go b/agent/setup.go index fcaac84766..21509b7999 100644 --- a/agent/setup.go +++ b/agent/setup.go @@ -20,6 +20,7 @@ import ( "github.com/hashicorp/consul/logging" "github.com/hashicorp/consul/tlsutil" "github.com/hashicorp/go-hclog" + "google.golang.org/grpc/grpclog" ) // TODO: BaseDeps should be renamed in the future once more of Agent.Start @@ -66,6 +67,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer) (BaseDeps, error) if err != nil { return d, err } + grpclog.SetLoggerV2(logging.NewGRPCLogger(cfg.LogLevel, d.Logger)) for _, w := range warnings { d.Logger.Warn(w) diff --git a/logging/grpc.go b/logging/grpc.go index 27264c3826..53188bd376 100644 --- a/logging/grpc.go +++ b/logging/grpc.go @@ -17,7 +17,7 @@ type GRPCLogger struct { // logger with Severity/Verbosity level appropriate for the given config. // // Note that grpclog has Info, Warning, Error, Fatal severity levels AND integer -// verbosity levels for additional info. Verbose logs in glog are always INFO +// verbosity levels for additional info. Verbose logs in hclog are always DEBUG // severity so we map Info,V0 to INFO, Info,V1 to DEBUG, and Info,V>1 to TRACE. func NewGRPCLogger(logLevel string, logger hclog.Logger) *GRPCLogger { return &GRPCLogger{