sing-box/log/override.go

20 lines
419 B
Go
Raw Normal View History

2022-08-03 10:55:39 +00:00
package log
import (
"context"
)
type overrideLevelKey struct{}
func ContextWithOverrideLevel(ctx context.Context, level Level) context.Context {
return context.WithValue(ctx, (*overrideLevelKey)(nil), level)
}
func OverrideLevelFromContext(origin Level, ctx context.Context) Level {
level, loaded := ctx.Value((*overrideLevelKey)(nil)).(Level)
2023-02-21 06:53:00 +00:00
if !loaded || origin > level {
2022-08-03 10:55:39 +00:00
return origin
}
return level
}