feature/318_add_logs #319
2 changed files with 20 additions and 8 deletions
|
@ -239,8 +239,10 @@ func AddBucketName(l *zap.Logger) Func {
|
||||||
reqInfo := GetReqInfo(ctx)
|
reqInfo := GetReqInfo(ctx)
|
||||||
reqInfo.BucketName = chi.URLParam(r, BucketURLPrm)
|
reqInfo.BucketName = chi.URLParam(r, BucketURLPrm)
|
||||||
|
|
||||||
reqLogger := reqLogOrDefault(ctx, l)
|
if reqInfo.BucketName != "" {
|
||||||
r = r.WithContext(SetReqLogger(ctx, reqLogger.With(zap.String("bucket", reqInfo.BucketName))))
|
reqLogger := reqLogOrDefault(ctx, l)
|
||||||
|
r = r.WithContext(SetReqLogger(ctx, reqLogger.With(zap.String("bucket", reqInfo.BucketName))))
|
||||||
|
}
|
||||||
|
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
@ -270,7 +272,9 @@ func AddObjectName(l *zap.Logger) Func {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = r.WithContext(SetReqLogger(ctx, reqLogger.With(zap.String("object", reqInfo.ObjectName))))
|
if reqInfo.ObjectName != "" {
|
||||||
|
r = r.WithContext(SetReqLogger(ctx, reqLogger.With(zap.String("object", reqInfo.ObjectName))))
|
||||||
|
}
|
||||||
|
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
|
@ -312,12 +312,20 @@ func LogSuccessResponse(l *zap.Logger) Func {
|
||||||
reqLogger := reqLogOrDefault(ctx, l)
|
reqLogger := reqLogOrDefault(ctx, l)
|
||||||
reqInfo := GetReqInfo(ctx)
|
reqInfo := GetReqInfo(ctx)
|
||||||
|
|
||||||
fields := []zap.Field{
|
fields := make([]zap.Field, 0, 6)
|
||||||
zap.String("method", reqInfo.API),
|
fields = append(fields,
|
||||||
zap.String("bucket", reqInfo.BucketName),
|
|
||||||
zap.String("object", reqInfo.ObjectName),
|
|
||||||
zap.Int("status", lw.statusCode),
|
zap.Int("status", lw.statusCode),
|
||||||
zap.String("description", http.StatusText(lw.statusCode))}
|
zap.String("description", http.StatusText(lw.statusCode)),
|
||||||
|
zap.String("method", reqInfo.API),
|
||||||
|
)
|
||||||
|
|
||||||
|
if reqInfo.BucketName != "" {
|
||||||
|
fields = append(fields, zap.String("bucket", reqInfo.BucketName))
|
||||||
|
}
|
||||||
|
if reqInfo.ObjectName != "" {
|
||||||
|
fields = append(fields, zap.String("object", reqInfo.ObjectName))
|
||||||
|
}
|
||||||
|
|
||||||
if traceID, err := trace.TraceIDFromHex(reqInfo.TraceID); err == nil && traceID.IsValid() {
|
if traceID, err := trace.TraceIDFromHex(reqInfo.TraceID); err == nil && traceID.IsValid() {
|
||||||
fields = append(fields, zap.String("trace_id", reqInfo.TraceID))
|
fields = append(fields, zap.String("trace_id", reqInfo.TraceID))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue