Logger: Add feature toggle for errors in HTTP request logs (#64425)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package errutil
|
||||
|
||||
import "context"
|
||||
|
||||
type LogLevel string
|
||||
|
||||
const (
|
||||
@@ -35,3 +37,36 @@ func (l LogLevel) LogFunc(logger LogInterface) func(msg string, ctx ...interface
|
||||
return logger.Error
|
||||
}
|
||||
}
|
||||
|
||||
func (l LogLevel) HighestOf(other LogLevel) LogLevel {
|
||||
if l.order() < other.order() {
|
||||
return other
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (l LogLevel) order() int {
|
||||
switch l {
|
||||
case LevelNever:
|
||||
return 0
|
||||
case LevelDebug:
|
||||
return 1
|
||||
case LevelInfo:
|
||||
return 2
|
||||
case LevelWarn:
|
||||
return 3
|
||||
default: // LevelUnknown and LevelError.
|
||||
return 4
|
||||
}
|
||||
}
|
||||
|
||||
type useUnifiedLogging struct{}
|
||||
|
||||
func SetUnifiedLogging(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, useUnifiedLogging{}, true)
|
||||
}
|
||||
|
||||
func HasUnifiedLogging(ctx context.Context) bool {
|
||||
v, ok := ctx.Value(useUnifiedLogging{}).(bool)
|
||||
return ok && v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user