From 091e3059eb9fc7b1a089006a7f87a8e7a67286b6 Mon Sep 17 00:00:00 2001 From: NHAS Date: Wed, 8 May 2024 10:24:16 +1200 Subject: [PATCH] Improve event logging --- internal/data/events.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/data/events.go b/internal/data/events.go index cf667da8..571087f2 100644 --- a/internal/data/events.go +++ b/internal/data/events.go @@ -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) @@ -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) } }