From 8effc77788a201efe87636c94e16436da26b5199 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Tue, 17 Sep 2024 19:35:47 +0000 Subject: [chore] improved federatingdb logging in cases of unknown iri / types (#3313) * improved federatingdb logging in cases of unknown iri / types, add new log methods * whoops; forgot to wrap log argument in serialize{} ! * use debug instead of warn level * switch last entry to Debug --- internal/federation/federatingdb/util.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'internal/federation/federatingdb/util.go') diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go index 43d811914..6660bd06a 100644 --- a/internal/federation/federatingdb/util.go +++ b/internal/federation/federatingdb/util.go @@ -23,7 +23,7 @@ import ( "fmt" "net/url" - "codeberg.org/gruf/go-logger/v2/level" + "codeberg.org/gruf/go-byteutil" "github.com/superseriousbusiness/activity/streams" "github.com/superseriousbusiness/activity/streams/vocab" "github.com/superseriousbusiness/gotosocial/internal/ap" @@ -91,15 +91,7 @@ func sameActor(actor1 vocab.ActivityStreamsActorProperty, actor2 vocab.ActivityS // The go-fed library will handle setting the 'id' property on the // activity or object provided with the value returned. func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) { - if log.Level() >= level.DEBUG { - i, err := marshalItem(t) - if err != nil { - return nil, err - } - l := log.WithContext(ctx). - WithField("newID", i) - l.Debug("entering NewID") - } + log.DebugKV(ctx, "newID", serialize{t}) // Most of our types set an ID already // by this point, return this if found. @@ -268,16 +260,20 @@ func getActivityContext(ctx context.Context) activityContext { } } -func marshalItem(item vocab.Type) (string, error) { - m, err := ap.Serialize(item) +// serialize wraps a vocab.Type to provide +// lazy-serialization along with error output. +type serialize struct{ item vocab.Type } + +func (s serialize) String() string { + m, err := ap.Serialize(s.item) if err != nil { - return "", err + return "!(error serializing item: " + err.Error() + ")" } b, err := json.Marshal(m) if err != nil { - return "", err + return "!(error json marshaling item: " + err.Error() + ")" } - return string(b), nil + return byteutil.B2S(b) } -- cgit v1.2.3