From e889545210069831e308c2051e36e919fd833a08 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 10 Apr 2024 00:06:50 +0300 Subject: [PATCH] fixup logger Signed-off-by: Vasiliy Tolstov --- handler/health/health.go | 2 +- handler/meter/meter.go | 2 +- handler/pprof/pprof.go | 2 +- handler/swagger-ui/swaggerui.go | 2 +- handler/swagger/swagger.go | 2 +- http.go | 21 ++++++++++----------- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/handler/health/health.go b/handler/health/health.go index 4399cf3..e1e0dda 100644 --- a/handler/health/health.go +++ b/handler/health/health.go @@ -1,4 +1,4 @@ -package health // import "go.unistack.org/micro-server-http/v3/handler/health" +package health_handler import ( "context" diff --git a/handler/meter/meter.go b/handler/meter/meter.go index 986e215..8ee02f0 100644 --- a/handler/meter/meter.go +++ b/handler/meter/meter.go @@ -1,4 +1,4 @@ -package meter // import "go.unistack.org/micro-server-http/v3/handler/meter" +package meter_handler import ( "bytes" diff --git a/handler/pprof/pprof.go b/handler/pprof/pprof.go index 636eab1..d74f637 100644 --- a/handler/pprof/pprof.go +++ b/handler/pprof/pprof.go @@ -1,4 +1,4 @@ -package pprof +package pprof_handler import ( "expvar" diff --git a/handler/swagger-ui/swaggerui.go b/handler/swagger-ui/swaggerui.go index 3a30c69..cd486db 100644 --- a/handler/swagger-ui/swaggerui.go +++ b/handler/swagger-ui/swaggerui.go @@ -1,4 +1,4 @@ -package swaggerui // import "go.unistack.org/micro-server-http/v3/handler/swagger-ui" +package swaggerui_handler import ( "embed" diff --git a/handler/swagger/swagger.go b/handler/swagger/swagger.go index 15533d8..5daf7d1 100644 --- a/handler/swagger/swagger.go +++ b/handler/swagger/swagger.go @@ -1,4 +1,4 @@ -package swagger +package swagger_handler import ( "io/fs" diff --git a/http.go b/http.go index 1cc09a4..52fa01d 100644 --- a/http.go +++ b/http.go @@ -35,7 +35,6 @@ type Server struct { pathHandlers *rhttp.Trie opts server.Options registerRPC bool - registerCORS bool sync.RWMutex registered bool init bool @@ -518,7 +517,7 @@ func (h *Server) Start() error { } 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() @@ -562,7 +561,7 @@ func (h *Server) Start() error { if err := config.RegisterCheck(h.opts.Context); err != nil { 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 { if err = h.Register(); err != nil { @@ -594,7 +593,7 @@ func (h *Server) Start() error { go func() { 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 if rerr != nil && registered { 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 if err := h.Deregister(); err != nil { 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 { 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 } if err := h.Register(); err != nil { 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 { - config.Logger.Errorf(config.Context, "Server register error: %s", err) + config.Logger.Error(config.Context, "Server register error", err) } // wait for exit case ch = <-h.exit: @@ -653,11 +652,11 @@ func (h *Server) Start() error { // deregister 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 { - 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)