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.
This commit is contained in:
Daniel Nephin 2020-08-19 12:25:38 -04:00
parent 7349018ff3
commit e4578aace8
3 changed files with 3 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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{