Pass a logger to ConnPool and yamux, instead of an io.Writer
Allowing us to remove the LogOutput field from config.
This commit is contained in:
parent
7c4566f116
commit
73493ca01b
|
@ -591,16 +591,10 @@ func (a *Agent) initializeConnectionPool() error {
|
|||
rpcSrcAddr = &net.TCPAddr{IP: a.config.RPCBindAddr.IP}
|
||||
}
|
||||
|
||||
// Ensure we have a log output for the connection pool.
|
||||
logOutput := a.LogOutput
|
||||
if logOutput == nil {
|
||||
logOutput = os.Stderr
|
||||
}
|
||||
|
||||
pool := &pool.ConnPool{
|
||||
Server: a.config.ServerMode,
|
||||
SrcAddr: rpcSrcAddr,
|
||||
LogOutput: logOutput,
|
||||
Logger: a.logger.StandardLogger(&hclog.StandardLoggerOptions{InferLevels: true}),
|
||||
TLSConfigurator: a.tlsConfigurator,
|
||||
Datacenter: a.config.Datacenter,
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ func NewClientWithOptions(config *Config, options ...ConsulOption) (*Client, err
|
|||
connPool = &pool.ConnPool{
|
||||
Server: false,
|
||||
SrcAddr: config.RPCSrcAddr,
|
||||
LogOutput: config.LogOutput,
|
||||
Logger: logger.StandardLogger(&hclog.StandardLoggerOptions{InferLevels: true}),
|
||||
MaxTime: clientRPCConnMaxIdle,
|
||||
MaxStreams: clientMaxStreams,
|
||||
TLSConfigurator: tlsConfigurator,
|
||||
|
|
|
@ -295,7 +295,10 @@ func (s *Server) handleNativeTLS(conn net.Conn) {
|
|||
func (s *Server) handleMultiplexV2(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
conf := yamux.DefaultConfig()
|
||||
conf.LogOutput = s.config.LogOutput
|
||||
// override the default because LogOutput conflicts with Logger
|
||||
conf.LogOutput = nil
|
||||
// TODO: should this be created once and cached?
|
||||
conf.Logger = s.logger.StandardLogger(&hclog.StandardLoggerOptions{InferLevels: true})
|
||||
server, _ := yamux.Server(conn, conf)
|
||||
for {
|
||||
sub, err := server.Accept()
|
||||
|
|
|
@ -400,7 +400,7 @@ func NewServerWithOptions(config *Config, options ...ConsulOption) (*Server, err
|
|||
connPool = &pool.ConnPool{
|
||||
Server: true,
|
||||
SrcAddr: config.RPCSrcAddr,
|
||||
LogOutput: config.LogOutput,
|
||||
Logger: logger.StandardLogger(&hclog.StandardLoggerOptions{InferLevels: true}),
|
||||
MaxTime: serverRPCCache,
|
||||
MaxStreams: serverMaxStreams,
|
||||
TLSConfigurator: tlsConfigurator,
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"container/list"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/rpc"
|
||||
"sync"
|
||||
|
@ -126,8 +126,9 @@ type ConnPool struct {
|
|||
// SrcAddr is the source address for outgoing connections.
|
||||
SrcAddr *net.TCPAddr
|
||||
|
||||
// LogOutput is used to control logging
|
||||
LogOutput io.Writer
|
||||
// Logger passed to yamux
|
||||
// TODO: consider refactoring to accept a full yamux.Config instead of a logger
|
||||
Logger *log.Logger
|
||||
|
||||
// The maximum time to keep a connection open
|
||||
MaxTime time.Duration
|
||||
|
@ -454,9 +455,10 @@ func (p *ConnPool) getNewConn(dc string, nodeName string, addr net.Addr) (*Conn,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Setup the logger
|
||||
conf := yamux.DefaultConfig()
|
||||
conf.LogOutput = p.LogOutput
|
||||
// override the default because LogOutput conflicts with Logger.
|
||||
conf.LogOutput = nil
|
||||
conf.Logger = p.Logger
|
||||
|
||||
// Create a multiplexed session
|
||||
session, err := yamux.Client(conn, conf)
|
||||
|
|
Loading…
Reference in New Issue