[#224] Refactor logger tag configuration
All checks were successful
/ DCO (pull_request) Successful in 29s
/ Vulncheck (pull_request) Successful in 48s
/ Builds (pull_request) Successful in 1m21s
/ OCI image (pull_request) Successful in 1m55s
/ Lint (pull_request) Successful in 1m54s
/ Tests (pull_request) Successful in 51s
/ Integration tests (pull_request) Successful in 7m12s
/ Builds (push) Successful in 1m10s
/ Vulncheck (push) Successful in 1m5s
/ Lint (push) Successful in 3m8s
/ Tests (push) Successful in 1m9s
/ Integration tests (push) Successful in 5m51s
/ OCI image (push) Successful in 1m3s

Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
Pavel Pogodaev 2025-03-21 13:38:43 +03:00
parent f0b86c8ba7
commit cb72d11515
7 changed files with 59 additions and 28 deletions

View file

@ -40,7 +40,8 @@ type zapCoreTagFilterWrapper struct {
}
type TagFilterSettings interface {
LevelEnabled(tag string, lvl zapcore.Level) bool
LevelEnabled(tag string, tgtLevel zapcore.Level) bool
DefaultEnabled(lvl zapcore.Level) bool
}
func (c *zapCoreTagFilterWrapper) Enabled(level zapcore.Level) bool {
@ -63,24 +64,26 @@ func (c *zapCoreTagFilterWrapper) Check(entry zapcore.Entry, checked *zapcore.Ch
}
func (c *zapCoreTagFilterWrapper) Write(entry zapcore.Entry, fields []zapcore.Field) error {
if c.shouldSkip(entry, fields) || c.shouldSkip(entry, c.extra) {
if c.shouldSkip(entry, fields, c.extra) {
return nil
}
return c.core.Write(entry, fields)
}
func (c *zapCoreTagFilterWrapper) shouldSkip(entry zapcore.Entry, fields []zap.Field) bool {
func (c *zapCoreTagFilterWrapper) shouldSkip(entry zapcore.Entry, fields []zap.Field, extra []zap.Field) bool {
for _, field := range fields {
if field.Key == logs.TagFieldName && field.Type == zapcore.StringType {
if !c.settings.LevelEnabled(field.String, entry.Level) {
return true
}
break
return !c.settings.LevelEnabled(field.String, entry.Level)
}
}
for _, field := range extra {
if field.Key == logs.TagFieldName && field.Type == zapcore.StringType {
return !c.settings.LevelEnabled(field.String, entry.Level)
}
}
return false
return !c.settings.DefaultEnabled(entry.Level)
}
func (c *zapCoreTagFilterWrapper) Sync() error {