agent: use agent logger for consul client and deps

pull/3095/head
Frank Schroeder 2017-05-31 11:05:02 +02:00
parent c1e6a77c75
commit 4034d0ac0b
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 { if err := a.setupKeyrings(config); err != nil {
return nil, fmt.Errorf("Failed to configure keyring: %v", err) 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 { if err != nil {
return nil, fmt.Errorf("Failed to start Consul client: %v", err) 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 // NewClient is used to construct a new Consul client from the
// configuration, potentially returning an error // configuration, potentially returning an error
func NewClient(config *Config) (*Client, error) { func NewClient(config *Config) (*Client, error) {
return NewClientLogger(config, nil)
}
func NewClientLogger(config *Config, logger *log.Logger) (*Client, error) {
// Check the protocol version // Check the protocol version
if err := config.CheckProtocolVersion(); err != nil { if err := config.CheckProtocolVersion(); err != nil {
return nil, err return nil, err
@ -110,7 +114,9 @@ func NewClient(config *Config) (*Client, error) {
} }
// Create a logger // Create a logger
logger := log.New(config.LogOutput, "", log.LstdFlags) if logger == nil {
logger = log.New(config.LogOutput, "", log.LstdFlags)
}
// Create server // Create server
c := &Client{ 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.Tags["build"] = c.config.Build
conf.MemberlistConfig.LogOutput = c.config.LogOutput conf.MemberlistConfig.LogOutput = c.config.LogOutput
conf.LogOutput = c.config.LogOutput conf.LogOutput = c.config.LogOutput
conf.Logger = c.logger
conf.EventCh = ch conf.EventCh = ch
conf.SnapshotPath = filepath.Join(c.config.DataDir, path) conf.SnapshotPath = filepath.Join(c.config.DataDir, path)
conf.ProtocolVersion = protocolVersionMap[c.config.ProtocolVersion] 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 // NewServer is used to construct a new Consul server from the
// configuration, potentially returning an error // 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. // Check the protocol version.
if err := config.CheckProtocolVersion(); err != nil { if err := config.CheckProtocolVersion(); err != nil {
return nil, err return nil, err
@ -236,7 +236,6 @@ func NewServerLogger(config *Config, l *log.Logger) (*Server, error) {
if config.LogOutput == nil { if config.LogOutput == nil {
config.LogOutput = os.Stderr config.LogOutput = os.Stderr
} }
logger := l
if logger == nil { if logger == nil {
logger = log.New(config.LogOutput, "", log.LstdFlags) logger = log.New(config.LogOutput, "", log.LstdFlags)
} }