diff --git a/config.go b/config.go index a7fd817..8b67529 100644 --- a/config.go +++ b/config.go @@ -35,6 +35,8 @@ type Config struct { AdvertiseAddress string // Peers is a local cache of peer members Peers []string + // Debug output for memberlist + Debug bool } func (a *Agent) Config() *Config { @@ -58,9 +60,9 @@ func (cfg *Config) memberListConfig(peerUpdateChan chan bool, nodeEventChan chan mc.Delegate = NewAgentDelegate(cfg.NodeName, cfg.Address, peerUpdateChan, nodeEventChan) mc.Events = NewEventHandler(nodeEventChan) - // disable logging for memberlist - // TODO: enable if debug - mc.Logger = log.New(ioutil.Discard, "", 0) + if !cfg.Debug { + mc.Logger = log.New(ioutil.Discard, "", 0) + } host, port, err := net.SplitHostPort(cfg.ClusterAddress) if err != nil { diff --git a/start.go b/start.go index 2ecde43..b4d9488 100644 --- a/start.go +++ b/start.go @@ -7,7 +7,7 @@ import ( ) // Start handles cluster events -func (a *Agent) Start(s chan os.Signal) { +func (a *Agent) Start(s chan os.Signal) error { go func() { for range a.peerUpdateChan { if err := a.members.UpdateNode(nodeUpdateTimeout); err != nil { @@ -15,4 +15,10 @@ func (a *Agent) Start(s chan os.Signal) { } } }() + if len(a.config.Peers) > 0 { + if _, err := a.members.Join(a.config.Peers); err != nil { + return err + } + } + return nil }