Skip to content

Commit

Permalink
support config-strict on windows too
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Klyaus authored and fujita committed Dec 2, 2024
1 parent fb7102b commit 284e1e9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cmd/gobgpd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion cmd/gobgpd/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/server_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 284e1e9

Please sign in to comment.