Skip to content

Commit

Permalink
Streamline zap.* log context keys
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Apr 18, 2024
1 parent b63dc92 commit 271c0ba
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions internal/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ func (r *RuntimeConfig) GetSourceFromCredentials(user, pass string, logger *logg

sourceIdRaw, sourceIdOk := strings.CutPrefix(user, "source-")
if !sourceIdOk {
logger.Debugw("Cannot extract source ID from HTTP basic auth username", zap.String("user-input", user))
logger.Debugw("Cannot extract source ID from HTTP basic auth username", zap.String("user_input", user))
return nil
}
sourceId, err := strconv.ParseInt(sourceIdRaw, 10, 64)
if err != nil {
logger.Debugw("Cannot convert extracted source Id to int", zap.String("user-input", user), zap.Error(err))
logger.Debugw("Cannot convert extracted source Id to int", zap.String("user_input", user), zap.Error(err))
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/icinga2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (client *Client) startCatchupWorkers(delay time.Duration) (chan *catchupEve
if err != nil && !errors.Is(err, context.Canceled) {
client.Logger.Debugw("Catch-up-phase event worker failed",
zap.Stringer("worker", workerId),
zap.String("object type", objType),
zap.String("object_type", objType),
zap.Error(err))
}
return err
Expand Down Expand Up @@ -364,7 +364,7 @@ func (client *Client) worker() {
client.Logger.Debugw("Event to be replayed is not in cache", zap.Stringer("event", ev))
} else if ev.Time.Before(ts) {
client.Logger.Debugw("Skip replaying outdated Event Stream event", zap.Stringer("event", ev),
zap.Time("event timestamp", ev.Time), zap.Time("cache timestamp", ts))
zap.Time("event_timestamp", ev.Time), zap.Time("cache_timestamp", ts))
break
}

Expand Down
4 changes: 2 additions & 2 deletions internal/icinga2/client_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func (client *Client) checkMissedChanges(ctx context.Context, objType string, ca
var stateChangeEvents, acknowledgementEvents int
defer func() {
client.Logger.Debugw("Querying API emitted events",
zap.String("object type", objType),
zap.Int("state changes", stateChangeEvents),
zap.String("object_type", objType),
zap.Int("state_changes", stateChangeEvents),
zap.Int("acknowledgements", acknowledgementEvents))
}()

Expand Down
6 changes: 3 additions & 3 deletions internal/icinga2/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (launcher *Launcher) Launch(src *config.Source) {

if !launcher.isReady {
launcher.Logs.GetChildLogger("icinga2").
With(zap.Int64("source-id", src.ID)).
With(zap.Int64("source_id", src.ID)).
Debug("Postponing Event Stream Client Launch as Launcher is not ready yet")
launcher.waitingSources = append(launcher.waitingSources, src)
return
Expand All @@ -57,7 +57,7 @@ func (launcher *Launcher) Ready() {
launcher.isReady = true
for _, src := range launcher.waitingSources {
launcher.Logs.GetChildLogger("icinga2").
With(zap.Int64("source-id", src.ID)).
With(zap.Int64("source_id", src.ID)).
Debug("Launching postponed Event Stream Client")
launcher.launch(src)
}
Expand All @@ -66,7 +66,7 @@ func (launcher *Launcher) Ready() {

// launch a new Icinga 2 Event Stream API Client based on the config.Source configuration.
func (launcher *Launcher) launch(src *config.Source) {
logger := launcher.Logs.GetChildLogger("icinga2").With(zap.Int64("source-id", src.ID))
logger := launcher.Logs.GetChildLogger("icinga2").With(zap.Int64("source_id", src.ID))

if src.Type != config.SourceTypeIcinga2 ||
!src.Icinga2BaseURL.Valid ||
Expand Down
2 changes: 1 addition & 1 deletion internal/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {
msg = fmt.Sprintf(format, a...)
}

logger := l.logger.With(zap.Int("status-code", statusCode), zap.String("msg", msg))
logger := l.logger.With(zap.Int("status_code", statusCode), zap.String("msg", msg))
if ev != nil {
logger = logger.With(zap.Stringer("event", ev))
}
Expand Down

0 comments on commit 271c0ba

Please sign in to comment.