api/router/registry: use logger (#1402)

* api/router/registry: use logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* api/server/acme: use logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-03-24 23:45:11 +03:00
parent e15ad46e01
commit c580879955

View File

@ -4,7 +4,6 @@ package registry
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
@ -13,6 +12,7 @@ import (
"github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api"
"github.com/micro/go-micro/v2/api/router" "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"
"github.com/micro/go-micro/v2/registry/cache" "github.com/micro/go-micro/v2/registry/cache"
) )
@ -68,7 +68,9 @@ func (r *registryRouter) refresh() {
services, err := r.opts.Registry.ListServices() services, err := r.opts.Registry.ListServices()
if err != nil { if err != nil {
attempts++ 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) time.Sleep(time.Duration(attempts) * time.Second)
continue continue
} }
@ -83,6 +85,9 @@ func (r *registryRouter) refresh() {
} }
service, err := r.rc.GetService(s.Name) service, err := r.rc.GetService(s.Name)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Errorf("unable to get service: %v", err)
}
continue continue
} }
r.store(service) r.store(service)
@ -107,6 +112,9 @@ func (r *registryRouter) process(res *registry.Result) {
// get entry from cache // get entry from cache
service, err := r.rc.GetService(res.Service.Name) service, err := r.rc.GetService(res.Service.Name)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Errorf("unable to get service: %v", err)
}
return return
} }
@ -136,6 +144,9 @@ func (r *registryRouter) store(services []*registry.Service) {
// if we got nothing skip // if we got nothing skip
if err := api.Validate(end); err != nil { if err := api.Validate(end); err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Errorf("endpoint validation failed: %v", err)
}
continue continue
} }
@ -188,7 +199,9 @@ func (r *registryRouter) watch() {
w, err := r.opts.Registry.Watch() w, err := r.opts.Registry.Watch()
if err != nil { if err != nil {
attempts++ 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) time.Sleep(time.Duration(attempts) * time.Second)
continue continue
} }
@ -211,7 +224,9 @@ func (r *registryRouter) watch() {
// process next event // process next event
res, err := w.Next() res, err := w.Next()
if err != nil { 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) close(ch)
break break
} }