[#230] Refactor logger tag configuration
Some checks failed
/ DCO (pull_request) Successful in 35s
/ Vulncheck (pull_request) Failing after 58s
/ Builds (pull_request) Successful in 1m10s
/ OCI image (pull_request) Successful in 1m50s
/ Lint (pull_request) Successful in 1m56s
/ Tests (pull_request) Successful in 54s
/ Integration tests (pull_request) Successful in 5m56s
Some checks failed
/ DCO (pull_request) Successful in 35s
/ Vulncheck (pull_request) Failing after 58s
/ Builds (pull_request) Successful in 1m10s
/ OCI image (pull_request) Successful in 1m50s
/ Lint (pull_request) Successful in 1m56s
/ Tests (pull_request) Successful in 54s
/ Integration tests (pull_request) Successful in 5m56s
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
parent
273459e090
commit
1d82686b8e
3 changed files with 4 additions and 13 deletions
|
@ -198,17 +198,11 @@ func (t *tagsConfig) update(cfg *viper.Viper, ll zapcore.Level) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.tagLogs.Range(func(key, value any) bool {
|
t.tagLogs.Range(func(key, _ any) bool {
|
||||||
k := key.(string)
|
k := key.(string)
|
||||||
v := value.(zapcore.Level)
|
|
||||||
|
|
||||||
if lvl, ok := tags[k]; ok {
|
if _, ok := tags[k]; !ok {
|
||||||
if lvl != v {
|
|
||||||
t.tagLogs.Store(key, lvl)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.tagLogs.Delete(key)
|
t.tagLogs.Delete(key)
|
||||||
delete(tags, k)
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
|
@ -40,7 +40,7 @@ type zapCoreTagFilterWrapper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagFilterSettings interface {
|
type TagFilterSettings interface {
|
||||||
LevelEnabled(tag string, tgtLevel zapcore.Level) bool
|
LevelEnabled(tag string, lvl zapcore.Level) bool
|
||||||
DefaultEnabled(lvl zapcore.Level) bool
|
DefaultEnabled(lvl zapcore.Level) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +130,13 @@ func newLogEncoder() zapcore.Encoder {
|
||||||
//
|
//
|
||||||
// See also zapcore.Level, zap.NewProductionConfig, zap.AddStacktrace.
|
// See also zapcore.Level, zap.NewProductionConfig, zap.AddStacktrace.
|
||||||
func newStdoutLogger(v *viper.Viper, lvl zap.AtomicLevel, loggerSettings LoggerAppSettings, tagSetting TagFilterSettings) *Logger {
|
func newStdoutLogger(v *viper.Viper, lvl zap.AtomicLevel, loggerSettings LoggerAppSettings, tagSetting TagFilterSettings) *Logger {
|
||||||
stdout := zapcore.AddSync(os.Stderr)
|
stdout := zapcore.AddSync(os.Stdout)
|
||||||
|
|
||||||
consoleOutCore := zapcore.NewCore(newLogEncoder(), stdout, lvl)
|
consoleOutCore := zapcore.NewCore(newLogEncoder(), stdout, lvl)
|
||||||
consoleOutCore = applyZapCoreMiddlewares(consoleOutCore, v, loggerSettings, tagSetting)
|
consoleOutCore = applyZapCoreMiddlewares(consoleOutCore, v, loggerSettings, tagSetting)
|
||||||
|
|
||||||
return &Logger{
|
return &Logger{
|
||||||
logger: zap.New(consoleOutCore, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel))),
|
logger: zap.New(consoleOutCore, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel))),
|
||||||
lvl: lvl,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +154,6 @@ func newJournaldLogger(v *viper.Viper, lvl zap.AtomicLevel, loggerSettings Logge
|
||||||
|
|
||||||
return &Logger{
|
return &Logger{
|
||||||
logger: zap.New(coreWithContext, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel))),
|
logger: zap.New(coreWithContext, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel))),
|
||||||
lvl: lvl,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,6 @@ var defaultTags = []string{logs.TagApp, logs.TagDatapath, logs.TagExternalStorag
|
||||||
|
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
lvl zap.AtomicLevel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type appCfg struct {
|
type appCfg struct {
|
||||||
|
|
Loading…
Add table
Reference in a new issue