From c580879955aec741e41dd8a2517f98af949d3cf8 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 24 Mar 2020 23:45:11 +0300 Subject: [PATCH] api/router/registry: use logger (#1402) * api/router/registry: use logger Signed-off-by: Vasiliy Tolstov * api/server/acme: use logger Signed-off-by: Vasiliy Tolstov --- registry.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/registry.go b/registry.go index 51cbd8f..a8e96d4 100644 --- a/registry.go +++ b/registry.go @@ -4,7 +4,6 @@ package registry import ( "errors" "fmt" - "log" "net/http" "regexp" "strings" @@ -13,6 +12,7 @@ import ( "github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api/router" + "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/registry/cache" ) @@ -68,7 +68,9 @@ func (r *registryRouter) refresh() { services, err := r.opts.Registry.ListServices() if err != nil { attempts++ - log.Println("Error listing endpoints", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("unable to list services: %v", err) + } time.Sleep(time.Duration(attempts) * time.Second) continue } @@ -83,6 +85,9 @@ func (r *registryRouter) refresh() { } service, err := r.rc.GetService(s.Name) if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("unable to get service: %v", err) + } continue } r.store(service) @@ -107,6 +112,9 @@ func (r *registryRouter) process(res *registry.Result) { // get entry from cache service, err := r.rc.GetService(res.Service.Name) if err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("unable to get service: %v", err) + } return } @@ -136,6 +144,9 @@ func (r *registryRouter) store(services []*registry.Service) { // if we got nothing skip if err := api.Validate(end); err != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("endpoint validation failed: %v", err) + } continue } @@ -188,7 +199,9 @@ func (r *registryRouter) watch() { w, err := r.opts.Registry.Watch() if err != nil { attempts++ - log.Println("Error watching endpoints", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("error watching endpoints: %v", err) + } time.Sleep(time.Duration(attempts) * time.Second) continue } @@ -211,7 +224,9 @@ func (r *registryRouter) watch() { // process next event res, err := w.Next() if err != nil { - log.Println("Error getting next endpoint", err) + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("error getting next endoint: %v", err) + } close(ch) break }