From f92427bcf69ea22f28bbacf3914dc47807f4c8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Tue, 3 Mar 2020 02:25:47 +0800 Subject: [PATCH] Fix logging. --- pkg/visor/rpc.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index deba542f9a..7466db83b8 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -46,7 +46,7 @@ func newRPCServer(v *Visor, remoteName string) *rpc.Server { rpcS := rpc.NewServer() rpcG := &RPC{ visor: v, - log: v.Logger.PackageLogger("visor.RPC:" + remoteName), + log: v.Logger.PackageLogger("visor_rpc:" + remoteName), } if err := rpcS.RegisterName(RPCPrefix, rpcG); err != nil { panic(fmt.Errorf("failed to create visor RPC server: %v", err)) @@ -59,29 +59,24 @@ func (r *RPC) logReq(name string, in interface{}) func(out interface{}, err *err // Just in case r.log is not set. // However, this is dangerous in production as it may result in a race condition. if r.log == nil { - r.log = r.visor.Logger.PackageLogger("visor.RPC") + r.log = r.visor.Logger.PackageLogger("visor_rpc") } start := time.Now() - log := r.log. - WithField("received", start.Format(time.Kitchen)). - WithField("method", name) + log := r.log.WithField("req", name+"@"+start.Format(time.Kitchen)) if in != nil { log = log.WithField("req_in", in) } - log.Debug("Request received.") return func(out interface{}, err *error) { - log := log. - WithField("duration", time.Since(start).String()). - WithField("req", name) + //log := log.WithField("duration", time.Since(start).String()) if out != nil { log = log.WithField("req_out", out) } if err != nil { log = log.WithError(*err) } - log.Info("Request processed.") + log.Info("REQUEST:") } } @@ -423,7 +418,7 @@ func (r *RPC) DiscoverTransportByID(id *uuid.UUID, out *transport.EntryWithStatu // RoutingRules obtains all routing rules of the RoutingTable. func (r *RPC) RoutingRules(_ *struct{}, out *[]routing.Rule) (err error) { - defer r.logReq("AddTransport", nil)(out, &err) + defer r.logReq("RoutingRules", nil)(out, &err) *out = r.visor.router.Rules() return nil