fixup logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-04-10 00:06:50 +03:00
parent 526e414d60
commit e889545210
6 changed files with 15 additions and 16 deletions

View File

@ -1,4 +1,4 @@
package health // import "go.unistack.org/micro-server-http/v3/handler/health" package health_handler
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package meter // import "go.unistack.org/micro-server-http/v3/handler/meter" package meter_handler
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package pprof package pprof_handler
import ( import (
"expvar" "expvar"

View File

@ -1,4 +1,4 @@
package swaggerui // import "go.unistack.org/micro-server-http/v3/handler/swagger-ui" package swaggerui_handler
import ( import (
"embed" "embed"

View File

@ -1,4 +1,4 @@
package swagger package swagger_handler
import ( import (
"io/fs" "io/fs"

21
http.go
View File

@ -35,7 +35,6 @@ type Server struct {
pathHandlers *rhttp.Trie pathHandlers *rhttp.Trie
opts server.Options opts server.Options
registerRPC bool registerRPC bool
registerCORS bool
sync.RWMutex sync.RWMutex
registered bool registered bool
init bool init bool
@ -518,7 +517,7 @@ func (h *Server) Start() error {
} }
if config.Logger.V(logger.InfoLevel) { if config.Logger.V(logger.InfoLevel) {
config.Logger.Infof(config.Context, "Listening on %s", ts.Addr().String()) config.Logger.Info(config.Context, "Listening on "+ts.Addr().String())
} }
h.Lock() h.Lock()
@ -562,7 +561,7 @@ func (h *Server) Start() error {
if err := config.RegisterCheck(h.opts.Context); err != nil { if err := config.RegisterCheck(h.opts.Context); err != nil {
if config.Logger.V(logger.ErrorLevel) { if config.Logger.V(logger.ErrorLevel) {
config.Logger.Errorf(config.Context, "Server %s-%s register check error: %s", config.Name, config.ID, err) config.Logger.Error(config.Context, fmt.Sprintf("Server %s-%s register check error", config.Name, config.ID) err)
} }
} else { } else {
if err = h.Register(); err != nil { if err = h.Register(); err != nil {
@ -594,7 +593,7 @@ func (h *Server) Start() error {
go func() { go func() {
if cerr := hs.Serve(ts); cerr != nil && !errors.Is(cerr, net.ErrClosed) { if cerr := hs.Serve(ts); cerr != nil && !errors.Is(cerr, net.ErrClosed) {
h.opts.Logger.Error(h.opts.Context, cerr) h.opts.Logger.Error(h.opts.Context, "serve error", cerr)
} }
}() }()
@ -622,28 +621,28 @@ func (h *Server) Start() error {
// nolint: nestif // nolint: nestif
if rerr != nil && registered { if rerr != nil && registered {
if config.Logger.V(logger.ErrorLevel) { if config.Logger.V(logger.ErrorLevel) {
config.Logger.Errorf(config.Context, "Server %s-%s register check error: %s, deregister it", config.Name, config.ID, rerr) config.Logger.Error(config.Context,fmt.Sprintf("Server %s-%s register check error, deregister it", config.Name, config.ID), rerr)
} }
// deregister self in case of error // deregister self in case of error
if err := h.Deregister(); err != nil { if err := h.Deregister(); err != nil {
if config.Logger.V(logger.ErrorLevel) { if config.Logger.V(logger.ErrorLevel) {
config.Logger.Errorf(config.Context, "Server %s-%s deregister error: %s", config.Name, config.ID, err) config.Logger.Error(config.Context, fmt.Sprintf("Server %s-%s deregister error", config.Name, config.ID), err)
} }
} }
} else if rerr != nil && !registered { } else if rerr != nil && !registered {
if config.Logger.V(logger.ErrorLevel) { if config.Logger.V(logger.ErrorLevel) {
config.Logger.Errorf(config.Context, "Server %s-%s register check error: %s", config.Name, config.ID, rerr) config.Logger.Error(config.Context, fmt.Sprintf("Server %s-%s register check error", config.Name, config.ID), rerr)
} }
continue continue
} }
if err := h.Register(); err != nil { if err := h.Register(); err != nil {
if config.Logger.V(logger.ErrorLevel) { if config.Logger.V(logger.ErrorLevel) {
config.Logger.Errorf(config.Context, "Server %s-%s register error: %s", config.Name, config.ID, err) config.Logger.Error(config.Context, fmt.Sprintf("Server %s-%s register error: %s", config.Name, config.ID), err)
} }
} }
if err := h.Register(); err != nil { if err := h.Register(); err != nil {
config.Logger.Errorf(config.Context, "Server register error: %s", err) config.Logger.Error(config.Context, "Server register error", err)
} }
// wait for exit // wait for exit
case ch = <-h.exit: case ch = <-h.exit:
@ -653,11 +652,11 @@ func (h *Server) Start() error {
// deregister // deregister
if err := h.Deregister(); err != nil { if err := h.Deregister(); err != nil {
config.Logger.Errorf(config.Context, "Server deregister error: %s", err) config.Logger.Error(config.Context, "Server deregister error", err)
} }
if err := config.Broker.Disconnect(config.Context); err != nil { if err := config.Broker.Disconnect(config.Context); err != nil {
config.Logger.Errorf(config.Context, "Broker disconnect error: %s", err) config.Logger.Error(config.Context, "Broker disconnect error", err)
} }
ctx, cancel := context.WithTimeout(context.Background(), h.opts.GracefulTimeout) ctx, cancel := context.WithTimeout(context.Background(), h.opts.GracefulTimeout)