github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/spi/context.go (about) 1 package spi 2 3 import "context" 4 5 var LogContextKey = 1010010001 6 7 type LogContext struct { 8 Memos [][]byte 9 Properties []interface{} 10 } 11 12 func AddLogContext(ctx context.Context, key string, value interface{}) { 13 logContext, _ := ctx.Value(LogContextKey).(*LogContext) 14 if logContext == nil { 15 return 16 } 17 logContext.Properties = append(logContext.Properties, key) 18 logContext.Properties = append(logContext.Properties, value) 19 } 20 21 func GetLogContext(ctx context.Context) *LogContext { 22 logContext, _ := ctx.Value(LogContextKey).(*LogContext) 23 return logContext 24 }