Skip to content

Commit

Permalink
access log add column upstream code
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Oct 16, 2023
1 parent 6bd0adc commit baa661a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion filter/accessLog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
})
}
6 changes: 5 additions & 1 deletion log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
}
Expand Down

0 comments on commit baa661a

Please sign in to comment.