From 1700712f7f2f15a64ce7dd9f4f127e55078d7265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Sat, 25 Nov 2017 23:39:47 +0100 Subject: [PATCH] registry: log subscribe/unsubscribe messages only when the action actually takes place --- registry.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/registry.go b/registry.go index 4c3fd9a..98fead8 100644 --- a/registry.go +++ b/registry.go @@ -54,12 +54,6 @@ var voidRegistryItem = &RegistryItem{} // Subscribe allows to connect client with a given identifier. func (r *registry) Subscribe(identifier id.ID) { - r.logger.Log( - "level", 1, - "action", "subscribe", - "identifier", identifier, - ) - r.mu.Lock() defer r.mu.Unlock() @@ -67,6 +61,12 @@ func (r *registry) Subscribe(identifier id.ID) { return } + r.logger.Log( + "level", 1, + "action", "subscribe", + "identifier", identifier, + ) + r.items[identifier] = voidRegistryItem } @@ -93,12 +93,6 @@ func (r *registry) Subscriber(hostPort string) (id.ID, *Auth, bool) { // Unsubscribe removes client from registry and returns it's RegistryItem. func (r *registry) Unsubscribe(identifier id.ID) *RegistryItem { - r.logger.Log( - "level", 1, - "action", "unsubscribe", - "identifier", identifier, - ) - r.mu.Lock() defer r.mu.Unlock() @@ -107,6 +101,12 @@ func (r *registry) Unsubscribe(identifier id.ID) *RegistryItem { return nil } + r.logger.Log( + "level", 1, + "action", "unsubscribe", + "identifier", identifier, + ) + if i.Hosts != nil { for _, h := range i.Hosts { delete(r.hosts, h.Host)