From 24f8e6b137e5e4ce8a721b58e20be889029a4d69 Mon Sep 17 00:00:00 2001 From: miaolz123 Date: Thu, 9 Aug 2018 18:31:22 +0800 Subject: [PATCH] feat: add http server log --- http.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/http.go b/http.go index 60a92c7..db8070c 100644 --- a/http.go +++ b/http.go @@ -7,6 +7,7 @@ import ( "net/http" "sync" + "github.com/micro/go-log" "github.com/micro/go-micro/cmd" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/server" @@ -14,9 +15,10 @@ import ( type httpServer struct { sync.Mutex - opts server.Options - hd server.Handler - exit chan chan error + opts server.Options + hd server.Handler + exit chan chan error + registerOnce sync.Once } func init() { @@ -106,6 +108,10 @@ func (h *httpServer) Register() error { registry.RegisterTTL(opts.RegisterTTL), } + h.registerOnce.Do(func() { + log.Logf("Registering node: %s", opts.Name+"-"+opts.Id) + }) + return opts.Registry.Register(service, rOpts...) } @@ -114,6 +120,8 @@ func (h *httpServer) Deregister() error { opts := h.opts h.Unlock() + log.Logf("Deregistering node: %s", opts.Name+"-"+opts.Id) + service := serviceDef(opts) return opts.Registry.Deregister(service) } @@ -129,6 +137,8 @@ func (h *httpServer) Start() error { return err } + log.Logf("Listening on %s", ln.Addr().String()) + h.Lock() h.opts.Address = ln.Addr().String() h.Unlock()