Skip to content

Commit

Permalink
Improve event logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed May 7, 2024
1 parent 1251c58 commit 091e305
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions internal/data/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func RegisterEventListener[T any](path string, isPrefix bool, f func(key string,
}
}

go func(key []byte) {
go func(key, previous []byte) {
if err := f(string(key), currentValue, previousValue, state); err != nil {
log.Println("applying event failed: ", state, currentValue, "err:", err)
err = RaiseError(err, value)
Expand All @@ -120,8 +120,17 @@ func RegisterEventListener[T any](path string, isPrefix bool, f func(key string,
}
return
}
EventsQueue.Write([]byte(fmt.Sprintf("%s[%s]: %s", key, state, string(value))))
}(event.Kv.Key)

switch state {
case DELETED, CREATED:
EventsQueue.Write([]byte(fmt.Sprintf("%s[%s]", key, state)))

case MODIFIED:
EventsQueue.Write([]byte(fmt.Sprintf("%s[%s]: %s -> %s", key, state, string(previous), string(value))))

}

}(event.Kv.Key, event.PrevKv.Value)

}
}
Expand Down

0 comments on commit 091e305

Please sign in to comment.