agent: use agent logger for consul client and deps

This commit is contained in:
Frank Schroeder 2017-05-31 11:05:02 +02:00
parent 2588f22be7
commit b06c969deb
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
3 changed files with 10 additions and 4 deletions

View File

@ -861,7 +861,7 @@ func (a *Agent) makeClient() (*consul.Client, error) {
if err := a.setupKeyrings(config); err != nil {
return nil, fmt.Errorf("Failed to configure keyring: %v", err)
}
client, err := consul.NewClient(config)
client, err := consul.NewClientLogger(config, a.logger)
if err != nil {
return nil, fmt.Errorf("Failed to start Consul client: %v", err)
}

View File

@ -83,6 +83,10 @@ type Client struct {
// NewClient is used to construct a new Consul client from the
// configuration, potentially returning an error
func NewClient(config *Config) (*Client, error) {
return NewClientLogger(config, nil)
}
func NewClientLogger(config *Config, logger *log.Logger) (*Client, error) {
// Check the protocol version
if err := config.CheckProtocolVersion(); err != nil {
return nil, err
@ -110,7 +114,9 @@ func NewClient(config *Config) (*Client, error) {
}
// Create a logger
logger := log.New(config.LogOutput, "", log.LstdFlags)
if logger == nil {
logger = log.New(config.LogOutput, "", log.LstdFlags)
}
// Create server
c := &Client{
@ -152,6 +158,7 @@ func (c *Client) setupSerf(conf *serf.Config, ch chan serf.Event, path string) (
conf.Tags["build"] = c.config.Build
conf.MemberlistConfig.LogOutput = c.config.LogOutput
conf.LogOutput = c.config.LogOutput
conf.Logger = c.logger
conf.EventCh = ch
conf.SnapshotPath = filepath.Join(c.config.DataDir, path)
conf.ProtocolVersion = protocolVersionMap[c.config.ProtocolVersion]

View File

@ -216,7 +216,7 @@ func NewServer(config *Config) (*Server, error) {
// NewServer is used to construct a new Consul server from the
// configuration, potentially returning an error
func NewServerLogger(config *Config, l *log.Logger) (*Server, error) {
func NewServerLogger(config *Config, logger *log.Logger) (*Server, error) {
// Check the protocol version.
if err := config.CheckProtocolVersion(); err != nil {
return nil, err
@ -236,7 +236,6 @@ func NewServerLogger(config *Config, l *log.Logger) (*Server, error) {
if config.LogOutput == nil {
config.LogOutput = os.Stderr
}
logger := l
if logger == nil {
logger = log.New(config.LogOutput, "", log.LstdFlags)
}