From 638e8384b60bb9e5aabc1a726db23c7ba242ee84 Mon Sep 17 00:00:00 2001 From: eMeab <32988354+eMeab@users.noreply.github.com> Date: Thu, 14 Jan 2021 22:45:23 +0800 Subject: [PATCH] Optimized log (#167) --- app/dispatcher/default.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/app/dispatcher/default.go b/app/dispatcher/default.go index ea5c8fa1..36e63c25 100644 --- a/app/dispatcher/default.go +++ b/app/dispatcher/default.go @@ -263,16 +263,18 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. skipRoutePick = content.SkipRoutePick } - var inTag string + routingLink := routing_session.AsRoutingContext(ctx) + inTag := routingLink.GetInboundTag() + isPickRoute := false if d.router != nil && !skipRoutePick { - if route, err := d.router.PickRoute(routing_session.AsRoutingContext(ctx)); err == nil { - tag := route.GetOutboundTag() - inTag = route.GetInboundTag() - if h := d.ohm.GetHandler(tag); h != nil { - newError("taking detour [", tag, "] for [", destination, "]").WriteToLog(session.ExportIDToError(ctx)) + if route, err := d.router.PickRoute(routingLink); err == nil { + outTag := route.GetOutboundTag() + isPickRoute = true + if h := d.ohm.GetHandler(outTag); h != nil { + newError("taking detour [", outTag, "] for [", destination, "]").WriteToLog(session.ExportIDToError(ctx)) handler = h } else { - newError("non existing tag: ", tag).AtWarning().WriteToLog(session.ExportIDToError(ctx)) + newError("non existing outTag: ", outTag).AtWarning().WriteToLog(session.ExportIDToError(ctx)) } } else { newError("default route for ", destination).WriteToLog(session.ExportIDToError(ctx)) @@ -292,10 +294,18 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport. if accessMessage := log.AccessMessageFromContext(ctx); accessMessage != nil { if tag := handler.Tag(); tag != "" { - if inTag != "" { - accessMessage.Detour = inTag + " -> " + tag + if isPickRoute { + if inTag != "" { + accessMessage.Detour = inTag + " -> " + tag + } else { + accessMessage.Detour = tag + } } else { - accessMessage.Detour = tag + if inTag != "" { + accessMessage.Detour = inTag + " >> " + tag + } else { + accessMessage.Detour = tag + } } } log.Record(accessMessage)