From baa661ad0a7477b86a1e09fc488f8aa4b9eb8c1e Mon Sep 17 00:00:00 2001 From: arraykeys Date: Mon, 16 Oct 2023 15:11:12 +0800 Subject: [PATCH] access log add column upstream code --- filter/accessLog.go | 5 ++++- log/log.go | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/filter/accessLog.go b/filter/accessLog.go index 9e73a79c..de750d72 100644 --- a/filter/accessLog.go +++ b/filter/accessLog.go @@ -80,6 +80,7 @@ func doAccessLog(filterName string, role string, address string, totalTime int64 resCtx := response.GetRPCContext(true) // response code should be same as upstream responseCode := "" + metaUpstreamCode := resCtx.Meta.LoadOrEmpty(motan.MetaUpstreamCode) if resCtx.Meta != nil { responseCode = resCtx.Meta.LoadOrEmpty(motan.MetaUpstreamCode) } @@ -107,5 +108,7 @@ func doAccessLog(filterName string, role string, address string, totalTime int64 TotalTime: totalTime, //ms ResponseCode: responseCode, Success: exception == nil, - Exception: string(exceptionData)}) + Exception: string(exceptionData), + UpstreamCode: metaUpstreamCode, + }) } diff --git a/log/log.go b/log/log.go index 594bb0b7..d1d484bb 100644 --- a/log/log.go +++ b/log/log.go @@ -54,6 +54,7 @@ type AccessLogEntity struct { Success bool `json:"success"` ResponseCode string `json:"responseCode"` Exception string `json:"exception"` + UpstreamCode string `json:"upstream_code"` } type Logger interface { @@ -386,7 +387,8 @@ func (d *defaultLogger) doAccessLog(logObject *AccessLogEntity) { zap.Int64("totalTime", logObject.TotalTime), zap.Bool("success", logObject.Success), zap.String("responseCode", logObject.ResponseCode), - zap.String("exception", logObject.Exception)) + zap.String("exception", logObject.Exception), + zap.String("upstreamCode", logObject.UpstreamCode)) } else { var buffer bytes.Buffer buffer.WriteString(logObject.FilterName) @@ -416,6 +418,8 @@ func (d *defaultLogger) doAccessLog(logObject *AccessLogEntity) { buffer.WriteString(logObject.ResponseCode) buffer.WriteString("|") buffer.WriteString(logObject.Exception) + buffer.WriteString("|") + buffer.WriteString(logObject.UpstreamCode) d.accessLogger.Info(buffer.String()) } }