Logger: Add feature toggle for errors in HTTP request logs (#64425)

This commit is contained in:
Emil Tullstedt
2023-03-31 15:38:09 +02:00
committed by GitHub
parent 977a7e9a55
commit be9361cb9e
19 changed files with 488 additions and 199 deletions
+35
View File
@@ -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
}