From 284e1e907590bb137ca121fdf913c12defc78998 Mon Sep 17 00:00:00 2001 From: Sergey Klyaus Date: Mon, 9 Sep 2024 11:29:46 +0200 Subject: [PATCH] support config-strict on windows too --- cmd/gobgpd/util.go | 3 +-- cmd/gobgpd/util_windows.go | 9 ++++++++- pkg/config/server_config_test.go | 2 +- pkg/log/logger.go | 7 +++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/gobgpd/util.go b/cmd/gobgpd/util.go index afac40e9f..7e5e9b4da 100644 --- a/cmd/gobgpd/util.go +++ b/cmd/gobgpd/util.go @@ -114,8 +114,7 @@ func (l *builtinLogger) Panic(msg string, fields log.Fields) { } func (l *builtinLogger) Fatal(msg string, fields log.Fields) { - if facility, hasFacility := fields[log.FieldFacility]; - hasFacility && facility == log.FacilityConfig && !l.cfgStrict { + if fields.HasFacility(log.FacilityConfig) && !l.cfgStrict { // Backward compatibility with old behavior when any logical config error was treated as warning l.logger.WithFields(logrus.Fields(fields)).Warn(msg) return diff --git a/cmd/gobgpd/util_windows.go b/cmd/gobgpd/util_windows.go index 43f043b79..795237f97 100644 --- a/cmd/gobgpd/util_windows.go +++ b/cmd/gobgpd/util_windows.go @@ -29,10 +29,17 @@ func addSyslogHook(_, _ string) error { } type builtinLogger struct { - logger *logrus.Logger + logger *logrus.Logger + cfgStrict bool } func (l *builtinLogger) Panic(msg string, fields log.Fields) { + if fields.HasFacility(log.FacilityConfig) && !l.cfgStrict { + // Backward compatibility with old behavior when any logical config error was treated as warning + l.logger.WithFields(logrus.Fields(fields)).Warn(msg) + return + } + l.logger.WithFields(logrus.Fields(fields)).Panic(msg) } diff --git a/pkg/config/server_config_test.go b/pkg/config/server_config_test.go index 4c2cca423..2b787418e 100644 --- a/pkg/config/server_config_test.go +++ b/pkg/config/server_config_test.go @@ -18,7 +18,7 @@ type configErrorLogger struct { } func (l *configErrorLogger) Fatal(msg string, fields log.Fields) { - if facility, hasFacility := fields[log.FieldFacility]; hasFacility && facility == log.FacilityConfig { + if fields.HasFacility(log.FacilityConfig) { l.configErrors = append(l.configErrors, msg) l.DefaultLogger.Error(msg, fields) } else { diff --git a/pkg/log/logger.go b/pkg/log/logger.go index fc1572b03..fb978bc89 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -42,6 +42,13 @@ var ( type Fields map[string]interface{} +func (fields Fields) HasFacility(facility interface{}) bool { + if fieldsFacility, hasFacility := fields[FieldFacility]; hasFacility && fieldsFacility == facility { + return true + } + return false +} + type Logger interface { Panic(msg string, fields Fields) Fatal(msg string, fields Fields)