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:
parent
397a8638f4
commit
8100d26430
@ -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
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ package autocert
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2/api/server/acme"
|
"github.com/micro/go-micro/v2/api/server/acme"
|
||||||
|
"github.com/micro/go-micro/v2/logger"
|
||||||
"golang.org/x/crypto/acme/autocert"
|
"golang.org/x/crypto/acme/autocert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +31,9 @@ func (a *autocertProvider) TLSConfig(hosts ...string) (*tls.Config, error) {
|
|||||||
}
|
}
|
||||||
dir := cacheDir()
|
dir := cacheDir()
|
||||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||||
log.Printf("warning: autocert not using a cache: %v", err)
|
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
||||||
|
logger.Infof("warning: autocert not using a cache: %v", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
m.Cache = autocert.DirCache(dir)
|
m.Cache = autocert.DirCache(dir)
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,13 @@ package certmagic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"log"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mholt/certmagic"
|
"github.com/mholt/certmagic"
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2/api/server/acme"
|
"github.com/micro/go-micro/v2/api/server/acme"
|
||||||
|
"github.com/micro/go-micro/v2/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type certmagicProvider struct {
|
type certmagicProvider struct {
|
||||||
@ -58,7 +57,7 @@ func NewProvider(options ...acme.Option) acme.Provider {
|
|||||||
|
|
||||||
if opts.Cache != nil {
|
if opts.Cache != nil {
|
||||||
if _, ok := opts.Cache.(certmagic.Storage); !ok {
|
if _, ok := opts.Cache.(certmagic.Storage); !ok {
|
||||||
log.Fatal("ACME: cache provided doesn't implement certmagic's Storage interface")
|
logger.Fatal("ACME: cache provided doesn't implement certmagic's Storage interface")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user