mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
Add req-ID to logging
with this log format we can easily identify the logs per request Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
ed9330d2f6
commit
e395080cdc
@ -23,6 +23,9 @@ type contextKey string
|
||||
// CtxKey for context based logging
|
||||
var CtxKey = contextKey("ID")
|
||||
|
||||
// ReqID for logging request ID
|
||||
var ReqID = contextKey("Req-ID")
|
||||
|
||||
// Log helps in context based logging
|
||||
func Log(ctx context.Context, format string) string {
|
||||
id := ctx.Value(CtxKey)
|
||||
@ -30,5 +33,10 @@ func Log(ctx context.Context, format string) string {
|
||||
return format
|
||||
}
|
||||
a := fmt.Sprintf("ID: %v ", id)
|
||||
reqID := ctx.Value(ReqID)
|
||||
if reqID == nil {
|
||||
return a + format
|
||||
}
|
||||
a += fmt.Sprintf("Req-ID: %v ", reqID)
|
||||
return a + format
|
||||
}
|
||||
|
Reference in New Issue
Block a user