From d2cea5120e4d5eec3c81d804424fb8ddd5cf2c2d Mon Sep 17 00:00:00 2001 From: mleku Date: Thu, 11 Jan 2024 13:41:46 +0000 Subject: [PATCH] Refactor logging statements in various files Several log printing statements were revised for consistency. The standard logger, "log" is now used in all the different files, ensuring identical log output format and handling. Additionally, unused or unnecessary code related to logging was removed, and some minor adjustments were performed. --- cmd/algia/config.go | 2 +- cmd/algia/main.go | 14 -------- cmd/algia/profile.go | 34 +++++++++++--------- cmd/algia/timeline.go | 14 ++------ cmd/replicatrd/replicatr/websockethandler.go | 6 ++-- pkg/eventstore/badger/count.go | 4 +-- pkg/eventstore/badger/query.go | 6 ++-- pkg/go-nostr/envelope/envelopes_test.go | 2 +- pkg/go-nostr/event/event.go | 8 ++--- pkg/go-nostr/example/example.go | 11 ++++--- pkg/go-nostr/pools/pool.go | 7 ++-- pkg/go-nostr/relays/relay.go | 25 +++++++------- pkg/go-nostr/relays/subscription.go | 7 ++-- pkg/nostr/normalize/normalize.go | 15 ++++----- pkg/nostr/relay/relay.go | 8 ++--- pkg/relay/eventstore/badger/count.go | 4 +-- pkg/relay/eventstore/badger/query.go | 12 +++---- pkg/relay/handlers.go | 6 ++-- 18 files changed, 86 insertions(+), 99 deletions(-) diff --git a/cmd/algia/config.go b/cmd/algia/config.go index cd0a74a3..2549bbaa 100644 --- a/cmd/algia/config.go +++ b/cmd/algia/config.go @@ -92,7 +92,7 @@ func (cfg *C) GetFollows(profile string) (profiles Follows, e error) { mu.Unlock() m := make(Checklist) cfg.Do(rp, cfg.GetRelaysAndTags(pub, m, &mu)) - log.D.F("found %d followers\n", len(m)) + log.D.F("found %d followers", len(m)) if len(m) > 0 { var follows []string for k := range m { diff --git a/cmd/algia/main.go b/cmd/algia/main.go index 0414b8b5..110e49c1 100644 --- a/cmd/algia/main.go +++ b/cmd/algia/main.go @@ -264,20 +264,6 @@ func main() { HelpName: "profile", Action: doProfile, }, - { - Name: "powa", - Usage: "post ぽわ〜", - UsageText: appName + " powa", - HelpName: "powa", - Action: doPowa, - }, - { - Name: "puru", - Usage: "post ぷる", - UsageText: appName + " puru", - HelpName: "puru", - Action: doPuru, - }, { Name: "zap", Flags: []cli.Flag{ diff --git a/cmd/algia/profile.go b/cmd/algia/profile.go index 5068ee46..bc854322 100644 --- a/cmd/algia/profile.go +++ b/cmd/algia/profile.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "os" "github.com/Hubmakerlabs/replicatr/pkg/context" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/event" @@ -35,25 +34,22 @@ func doProfile(cCtx *cli.Context) (e error) { return fmt.Errorf("failed to parse pubkey from '%s'", user) } } - // get set-metadata f := filter.T{ Kinds: []int{event.KindProfileMetadata}, Authors: []string{pub}, Limit: 1, } - evs := cfg.Events(f) if len(evs) == 0 { return errors.New("cannot find user") } - if j { - fmt.Fprintln(os.Stdout, evs[0].Content) + fmt.Println(evs[0].Content) return nil } - var profile Profile - e = json.Unmarshal([]byte(evs[0].Content), &profile) + var p Profile + e = json.Unmarshal([]byte(evs[0].Content), &p) if log.Fail(e) { return e } @@ -61,13 +57,21 @@ func doProfile(cCtx *cli.Context) (e error) { if log.Fail(e) { return e } - fmt.Printf("Pubkey: %v\n", npub) - fmt.Printf("Name: %v\n", profile.Name) - fmt.Printf("DisplayName: %v\n", profile.DisplayName) - fmt.Printf("WebSite: %v\n", profile.Website) - fmt.Printf("Picture: %v\n", profile.Picture) - fmt.Printf("NIP-05: %v\n", profile.Nip05) - fmt.Printf("LUD-16: %v\n", profile.Lud16) - fmt.Printf("About: %v\n", profile.About) + fmt.Printf("Pubkey: %v\n"+ + "Name: %v\n"+ + "DisplayName: %v\n"+ + "WebSite: %v\n"+ + "Picture: %v\n"+ + "NIP-05: %v\n"+ + "LUD-16: %v\n"+ + "About:\n%v\n", + npub, + p.Name, + p.DisplayName, + p.Website, + p.Picture, + p.Nip05, + p.Lud16, + p.About) return nil } diff --git a/cmd/algia/timeline.go b/cmd/algia/timeline.go index e4b81572..538d2e38 100644 --- a/cmd/algia/timeline.go +++ b/cmd/algia/timeline.go @@ -738,9 +738,9 @@ func doTimeline(cCtx *cli.Context) (e error) { extra := cCtx.Bool("extra") cfg := cCtx.App.Metadata["config"].(*C) // get followers - followsMap, e := cfg.GetFollows(cCtx.String("a")) - if log.Fail(e) { - return e + var followsMap Follows + if followsMap, e = cfg.GetFollows(cCtx.String("a")); log.Fail(e) { + return } var follows []string for k := range followsMap { @@ -789,11 +789,3 @@ func postMsg(cCtx *cli.Context, msg string) (e error) { } return } - -func doPowa(cCtx *cli.Context) (e error) { - return postMsg(cCtx, "ぽわ〜") -} - -func doPuru(cCtx *cli.Context) (e error) { - return postMsg(cCtx, "(((( ˙꒳​˙ ))))プルプルプルプルプルプルプル") -} diff --git a/cmd/replicatrd/replicatr/websockethandler.go b/cmd/replicatrd/replicatr/websockethandler.go index d0e5564f..ce91cf32 100644 --- a/cmd/replicatrd/replicatr/websockethandler.go +++ b/cmd/replicatrd/replicatr/websockethandler.go @@ -30,7 +30,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { var conn *websocket.Conn conn, e = rl.upgrader.Upgrade(w, r, nil) if rl.E.Chk(e) { - rl.E.F("failed to upgrade websocket: %v\n", e) + rl.E.F("failed to upgrade websocket: %v", e) return } rl.clients.Store(conn, struct{}{}) @@ -226,7 +226,7 @@ func (rl *Relay) websocketReadMessages(c context.T, kill func(), websocket.CloseNoStatusReceived, // 1005 websocket.CloseAbnormalClosure, // 1006 ) { - rl.E.F("unexpected close error from %s: %v\n", + rl.E.F("unexpected close error from %s: %v", r.Header.Get("X-Forwarded-For"), e) } return @@ -249,7 +249,7 @@ func (rl *Relay) websocketWatcher(c context.T, kill func(), t *time.Ticker, ws * case <-t.C: if e = ws.WriteMessage(websocket.PingMessage, nil); rl.E.Chk(e) { if !strings.HasSuffix(e.Error(), "use of closed network connection") { - rl.E.F("error writing ping: %v; closing websocket\n", e) + rl.E.F("error writing ping: %v; closing websocket", e) } return } diff --git a/pkg/eventstore/badger/count.go b/pkg/eventstore/badger/count.go index 3ee4727b..5a0223ba 100644 --- a/pkg/eventstore/badger/count.go +++ b/pkg/eventstore/badger/count.go @@ -59,7 +59,7 @@ func (b *BadgerBackend) CountEvents(c context.T, f *filter.T) (int64, error) { return } log.D.F("badger: count (%v) failed to get %d from raw " + - "event store: %s\n", q, idx) + "event store: %s", q, idx) return } @@ -77,7 +77,7 @@ func (b *BadgerBackend) CountEvents(c context.T, f *filter.T) (int64, error) { return nil }) if log.Fail(e) { - log.D.F("badger: count value read error: %s\n", e) + log.D.F("badger: count value read error: %s", e) } } } diff --git a/pkg/eventstore/badger/query.go b/pkg/eventstore/badger/query.go index 772632bb..2a9ef4a0 100644 --- a/pkg/eventstore/badger/query.go +++ b/pkg/eventstore/badger/query.go @@ -75,14 +75,14 @@ func (b BadgerBackend) QueryEvents(c context.T, f *filter.T) (chan *event.T, err if e == badger.ErrDiscardedTxn { return } - log.D.F("badger: failed to get %x based on prefix %x, index key %x from raw event store: %s\n", + log.D.F("badger: failed to get %x based on prefix %x, index key %x from raw event store: %s", idx, q.prefix, key, e) return } item.Value(func(val []byte) (e error) { evt := &event.T{} if e := nostr_binary.Unmarshal(val, evt); e != nil { - log.D.F("badger: value read error (id %x): %s\n", val[0:32], e) + log.D.F("badger: value read error (id %x): %s", val[0:32], e) return e } @@ -160,7 +160,7 @@ func (b BadgerBackend) QueryEvents(c context.T, f *filter.T) (chan *event.T, err return nil }) if e != nil { - log.D.F("badger: query txn error: %s\n", e) + log.D.F("badger: query txn error: %s", e) } }() diff --git a/pkg/go-nostr/envelope/envelopes_test.go b/pkg/go-nostr/envelope/envelopes_test.go index 782ce48b..aedff80d 100644 --- a/pkg/go-nostr/envelope/envelopes_test.go +++ b/pkg/go-nostr/envelope/envelopes_test.go @@ -57,7 +57,7 @@ func TestParseMessage(t *testing.T) { return } if testCase.ExpectedEnvelope == nil && env != nil { - t.Fatalf("expected nil but got %v\n", env) + t.Fatalf("expected nil but got %v", env) } if testCase.ExpectedEnvelope.String() != env.String() { t.Fatalf("unexpected output:\n %s\n != %s", testCase.ExpectedEnvelope, env) diff --git a/pkg/go-nostr/event/event.go b/pkg/go-nostr/event/event.go index ac2f86cc..70457ad8 100644 --- a/pkg/go-nostr/event/event.go +++ b/pkg/go-nostr/event/event.go @@ -17,13 +17,13 @@ import ( ) type T struct { - ID string `json:"id"` + ID string `json:"id"` PubKey string `json:"pubkey"` CreatedAt timestamp.T `json:"created_at"` Kind int `json:"kind"` - Tags tags.Tags `json:"tags"` - Content string `json:"content"` - Sig string `json:"sig"` + Tags tags.Tags `json:"tags"` + Content string `json:"content"` + Sig string `json:"sig"` // anything here will be mashed together with the main event object when serializing extra map[string]any diff --git a/pkg/go-nostr/example/example.go b/pkg/go-nostr/example/example.go index 6e4b8366..988b8f94 100644 --- a/pkg/go-nostr/example/example.go +++ b/pkg/go-nostr/example/example.go @@ -9,6 +9,7 @@ import ( "time" "github.com/Hubmakerlabs/replicatr/pkg/context" + log2 "github.com/Hubmakerlabs/replicatr/pkg/log" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/event" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/filter" @@ -19,6 +20,8 @@ import ( "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/timestamp" ) +var log = log2.GetStd() + func main() { ctx, cancel := context.Timeout(context.Bg(), 3*time.Second) @@ -32,7 +35,7 @@ func main() { reader := os.Stdin var npub string var b [64]byte - fmt.Fprintf(os.Stderr, "using %s\n----\nexample subscription for three most recent notes mentioning user\npaste npub key: ", url) + log.D.F("using %s\n----\nexample subscription for three most recent notes mentioning user\npaste npub key: ", url) if n, e := reader.Read(b[:]); e == nil { npub = strings.TrimSpace(fmt.Sprintf("%s", b[:n])) } else { @@ -73,7 +76,7 @@ func main() { filename := "example_output.json" if f, e := os.Create(filename); e == nil { - fmt.Fprintf(os.Stderr, "returned events saved to %s\n", filename) + log.D.F("returned events saved to %s\n", filename) // encode the returned events in a file enc := json.NewEncoder(f) enc.SetIndent("", " ") @@ -83,7 +86,7 @@ func main() { panic(e) } - fmt.Fprintf(os.Stderr, "----\nexample publication of note.\npaste nsec key (leave empty to autogenerate): ") + log.D.F("----\nexample publication of note.\npaste nsec key (leave empty to autogenerate): ") var nsec string if n, e := reader.Read(b[:]); e == nil { nsec = strings.TrimSpace(fmt.Sprintf("%s", b[:n])) @@ -130,6 +133,6 @@ func main() { continue } fmt.Println("posting to: ", url) - rl.Publish(ctx, ev) + log.Fail(rl.Publish(ctx, &ev)) } } diff --git a/pkg/go-nostr/pools/pool.go b/pkg/go-nostr/pools/pool.go index 49258669..86ba759f 100644 --- a/pkg/go-nostr/pools/pool.go +++ b/pkg/go-nostr/pools/pool.go @@ -2,12 +2,12 @@ package pools import ( "fmt" - "log" "strings" "sync" "time" "github.com/Hubmakerlabs/replicatr/pkg/context" + log2 "github.com/Hubmakerlabs/replicatr/pkg/log" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/event" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/filter" @@ -17,6 +17,7 @@ import ( "github.com/Hubmakerlabs/replicatr/pkg/nostr/normalize" "github.com/puzpuzpuz/xsync/v2" ) +var log = log2.GetStd() const ( seenAlreadyDropTick = time.Minute @@ -195,7 +196,7 @@ func (pool *SimplePool) subMany(c context.T, urls []string, filters filters.T, u goto subscribe } } else { - log.Printf("CLOSED from %s: '%s'\n", nm, reason) + log.D.F("CLOSED from %s: '%s'", nm, reason) } return case <-c.Done(): @@ -273,7 +274,7 @@ func (pool *SimplePool) subManyEose(c context.T, urls []string, filters filters. goto subscribe } } - log.Printf("CLOSED from %s: '%s'\n", nm, reason) + log.D.F("CLOSED from %s: '%s'", nm, reason) return case evt, more := <-sub.Events: if !more { diff --git a/pkg/go-nostr/relays/relay.go b/pkg/go-nostr/relays/relay.go index ba517723..b92ee18a 100644 --- a/pkg/go-nostr/relays/relay.go +++ b/pkg/go-nostr/relays/relay.go @@ -3,13 +3,13 @@ package relays import ( "bytes" "fmt" - "log" "net/http" "sync" "sync/atomic" "time" "github.com/Hubmakerlabs/replicatr/pkg/context" + log2 "github.com/Hubmakerlabs/replicatr/pkg/log" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/OK" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/auth" @@ -31,6 +31,8 @@ import ( "github.com/puzpuzpuz/xsync/v2" ) +var log = log2.GetStd() + type Status int var subscriptionIDCounter atomic.Int32 @@ -178,18 +180,19 @@ func (r *Relay) Connect(c context.T) error { // queue all write operations here so we don't do mutex spaghetti go func() { + var e error for { select { case <-ticker.C: - e := wsutil.WriteClientMessage(r.Connection.Conn, ws.OpPing, nil) + e = wsutil.WriteClientMessage(r.Connection.Conn, ws.OpPing, nil) if e != nil { - fmt.Printf("{%s} error writing ping: %v; closing websocket", r.URL, e) + log.D.F("{%s} error writing ping: %v; closing websocket", r.URL, e) r.Close() // this should trigger a context cancelation return } case writeRequest := <-r.writeQueue: // all write requests will go through this to prevent races - if e := r.Connection.WriteMessage(writeRequest.msg); e != nil { + if e = r.Connection.WriteMessage(writeRequest.msg); e != nil { writeRequest.answer <- e } close(writeRequest.answer) @@ -213,7 +216,7 @@ func (r *Relay) Connect(c context.T) error { } message := buf.Bytes() - fmt.Printf("{%s} %v\n", r.URL, string(message)) + log.D.F("{%s} %v", r.URL, string(message)) envelope := envelope2.ParseMessage(message) if envelope == nil { continue @@ -225,7 +228,7 @@ func (r *Relay) Connect(c context.T) error { if r.notices != nil { r.notices <- string(*env) } else { - log.Printf("NOTICE from %s: '%s'\n", r.URL, string(*env)) + log.D.F("NOTICE from %s: '%s'", r.URL, string(*env)) } case *auth.Envelope: if env.Challenge == nil { @@ -237,13 +240,13 @@ func (r *Relay) Connect(c context.T) error { continue } if subscription, ok := r.Subscriptions.Load(*env.SubscriptionID); !ok { - fmt.Printf("{%s} no subscription with id '%s'\n", + log.D.F("{%s} no subscription with id '%s'", r.URL, *env.SubscriptionID) continue } else { // check if the event matches the desired filter, ignore otherwise if !subscription.Filters.Match(&env.T) { - fmt.Printf("{%s} filter does not match: %v ~ %v\n", + log.D.F("{%s} filter does not match: %v ~ %v", r.URL, subscription.Filters, env.T) continue } @@ -255,7 +258,7 @@ func (r *Relay) Connect(c context.T) error { if e != nil { errmsg = e.Error() } - fmt.Printf("{%s} bad signature on %s; %s\n", r.URL, env.T.ID, errmsg) + log.D.F("{%s} bad signature on %s; %s", r.URL, env.T.ID, errmsg) continue } } @@ -279,7 +282,7 @@ func (r *Relay) Connect(c context.T) error { if okCallback, exist := r.okCallbacks.Load(env.EventID); exist { okCallback(env.OK, env.Reason) } else { - fmt.Printf("{%s} got an unexpected OK message for event %s", r.URL, env.EventID) + log.D.F("{%s} got an unexpected OK message for event %s", r.URL, env.EventID) } } } @@ -354,7 +357,7 @@ func (r *Relay) publish(c context.T, id string, env envelopes.E) error { // publish event envb, _ := env.MarshalJSON() - fmt.Printf("{%s} sending %v\n", r.URL, string(envb)) + log.D.F("{%s} sending %v", r.URL, string(envb)) if e := <-r.Write(envb); e != nil { return e } diff --git a/pkg/go-nostr/relays/subscription.go b/pkg/go-nostr/relays/subscription.go index 50fdae01..fb3ccf87 100644 --- a/pkg/go-nostr/relays/subscription.go +++ b/pkg/go-nostr/relays/subscription.go @@ -7,7 +7,6 @@ import ( "sync/atomic" "github.com/Hubmakerlabs/replicatr/pkg/context" - close2 "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/closer" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/count" "github.com/Hubmakerlabs/replicatr/pkg/go-nostr/event" @@ -147,7 +146,7 @@ func (sub *Subscription) Close() { id := sub.GetID() closeMsg := close2.Envelope(id) closeb, _ := (&closeMsg).MarshalJSON() - fmt.Printf("{%s} sending %v", sub.Relay.URL, string(closeb)) + log.D.F("{%s} sending %v", sub.Relay.URL, string(closeb)) <-sub.Relay.Write(closeb) } } @@ -156,7 +155,7 @@ func (sub *Subscription) Close() { // The subscription will be closed if the context expires. func (sub *Subscription) Sub(_ context.T, filters filters.T) { sub.Filters = filters - sub.Fire() + log.Fail(sub.Fire()) } // Fire sends the "REQ" command to the relay. @@ -169,7 +168,7 @@ func (sub *Subscription) Fire() error { } else { reqb, _ = count.Envelope{id, sub.Filters, nil}.MarshalJSON() } - fmt.Printf("{%s} sending %v", sub.Relay.URL, string(reqb)) + log.D.F("{%s} sending %v", sub.Relay.URL, string(reqb)) sub.live.Store(true) if e := <-sub.Relay.Write(reqb); e != nil { diff --git a/pkg/nostr/normalize/normalize.go b/pkg/nostr/normalize/normalize.go index 10fa7fff..3f25f386 100644 --- a/pkg/nostr/normalize/normalize.go +++ b/pkg/nostr/normalize/normalize.go @@ -1,13 +1,15 @@ package normalize import ( - "fmt" "net/url" - "os" "strconv" "strings" + + log2 "github.com/Hubmakerlabs/replicatr/pkg/log" ) +var log = log2.GetStd() + // URL normalizes the URL // // - Adds wss:// to addresses without a port, or with 443 that have no protocol @@ -36,8 +38,7 @@ func URL(u string) string { strings.HasPrefix(u, "wss://")) { split := strings.Split(u, ":") if len(split) != 2 { - _, _ = fmt.Fprintf(os.Stderr, - "Error: more than one ':' in URL: '%s'\n", u) + log.D.F("Error: more than one ':' in URL: '%s'", u) // this is a malformed URL if it has more than one ":", return empty // since this function does not return an error explicitly. return "" @@ -45,14 +46,12 @@ func URL(u string) string { port, e := strconv.ParseInt(split[1], 10, 64) if e != nil { - _, _ = fmt.Fprintf(os.Stderr, - "Error normalizing URL '%s': %s\n", u, e) + log.D.F("Error normalizing URL '%s': %s", u, e) // again, without an error we must return nil return "" } if port > 65535 { - _, _ = fmt.Fprintf(os.Stderr, - "Port on address %d: greater than maximum 65535\n", port) + log.D.F("Port on address %d: greater than maximum 65535", port) return "" } // if the port is explicitly set to 443 we assume it is wss:// and drop diff --git a/pkg/nostr/relay/relay.go b/pkg/nostr/relay/relay.go index 1c753796..97f0f0f1 100644 --- a/pkg/nostr/relay/relay.go +++ b/pkg/nostr/relay/relay.go @@ -266,7 +266,7 @@ func (r *Relay) Connect(c context.T) (e error) { if r.notices != nil { r.notices <- env.Text } else { - log.D.F("NOTICE from %s: '%s'\n", r.URL, env.Text) + log.D.F("NOTICE from %s: '%s'", r.URL, env.Text) } case *auth2.Challenge: if env.Challenge == "" { @@ -297,7 +297,7 @@ func (r *Relay) Connect(c context.T) (e error) { if log.Fail(e) { msg = e.Error() } - log.E.F("{%s} bad signature: %s\n", r.URL, msg) + log.E.F("{%s} bad signature: %s", r.URL, msg) continue } } @@ -371,7 +371,7 @@ func (r *Relay) Publish(c context.T, evt *event.T) (s Status, e error) { defer r.okCallbacks.Delete(string(evt.ID)) // publish event envb, _ := (&event2.Envelope{Event: evt}).MarshalJSON() - log.D.F("{%s} sending %v\n", r.URL, string(envb)) + log.D.F("{%s} sending %v", r.URL, string(envb)) s = PublishStatusSent if e = <-r.Write(envb); log.Fail(e) { s = PublishStatusFailed @@ -430,7 +430,7 @@ func (r *Relay) Auth(c context.T, event *event.T) (s Status, e error) { defer r.okCallbacks.Delete(string(event.ID)) // send AUTH authResponse, _ := (&auth2.Response{T: event}).MarshalJSON() - log.D.F("{%s} sending %v\n", r.URL, string(authResponse)) + log.D.F("{%s} sending %v", r.URL, string(authResponse)) if e = <-r.Write(authResponse); e != nil { // s will be "failed" return s, e diff --git a/pkg/relay/eventstore/badger/count.go b/pkg/relay/eventstore/badger/count.go index 8791a565..4f4a420f 100644 --- a/pkg/relay/eventstore/badger/count.go +++ b/pkg/relay/eventstore/badger/count.go @@ -51,7 +51,7 @@ func (b *Backend) CountEvents(c context.T, f *filter.T) (cnt int64, e error) { if errors.Is(e, badger.ErrDiscardedTxn) { return } - log.E.F("badger: count (%v) failed to get %d from raw event store: %s\n", q, idx, e) + log.E.F("badger: count (%v) failed to get %d from raw event store: %s", q, idx, e) return } e = item.Value(func(val []byte) (e error) { @@ -66,7 +66,7 @@ func (b *Backend) CountEvents(c context.T, f *filter.T) (cnt int64, e error) { return nil }) if log.E.Chk(e) { - log.E.F("badger: count value read error: %s\n", e) + log.E.F("badger: count value read error: %s", e) } } } diff --git a/pkg/relay/eventstore/badger/query.go b/pkg/relay/eventstore/badger/query.go index f66eaea8..ca916b01 100644 --- a/pkg/relay/eventstore/badger/query.go +++ b/pkg/relay/eventstore/badger/query.go @@ -63,14 +63,14 @@ func (b *Backend) Q(queries []query, since uint32, extraFilter *filter.T, f *fil if errors.Is(e, badger.ErrDiscardedTxn) { return } - log.E.F("badger: failed to get %x based on prefix %x, index key %x from raw event store: %s\n", + log.E.F("badger: failed to get %x based on prefix %x, index key %x from raw event store: %s", idx, q.prefix, key, e) return } log.D.Chk(item.Value(func(val []byte) (e error) { evt := &event.T{} if e = nostr_binary.Unmarshal(val, evt); e != nil { - log.E.F("badger: value read error (id %x): %s\n", val[0:32], e) + log.E.F("badger: value read error (id %x): %s", val[0:32], e) return e } // check if this matches the other filters that were not part of the index @@ -135,7 +135,7 @@ func (b *Backend) Q(queries []query, since uint32, extraFilter *filter.T, f *fil return nil }) if log.E.Chk(e) { - log.E.F("badger: query txn error: %s\n", e) + log.E.F("badger: query txn error: %s", e) } } @@ -181,14 +181,14 @@ func (b *Backend) QueryEvents(c context.T, f *filter.T) (evChan chan *event.T, e if errors.Is(e, badger.ErrDiscardedTxn) { return } - log.E.F("badger: failed to get %x based on prefix %x, index key %x from raw event store: %s\n", + log.E.F("badger: failed to get %x based on prefix %x, index key %x from raw event store: %s", idx, q.prefix, key, e) return } log.D.Chk(item.Value(func(val []byte) (e error) { evt := &event.T{} if e = nostr_binary.Unmarshal(val, evt); e != nil { - log.E.F("badger: value read error (id %x): %s\n", val[0:32], e) + log.E.F("badger: value read error (id %x): %s", val[0:32], e) return e } // check if this matches the other filters that were not part of the index @@ -253,7 +253,7 @@ func (b *Backend) QueryEvents(c context.T, f *filter.T) (evChan chan *event.T, e return nil }) if log.E.Chk(e) { - log.E.F("badger: query txn error: %s\n", e) + log.E.F("badger: query txn error: %s", e) } }() return diff --git a/pkg/relay/handlers.go b/pkg/relay/handlers.go index a7262203..9ab65572 100644 --- a/pkg/relay/handlers.go +++ b/pkg/relay/handlers.go @@ -48,7 +48,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { var e error var conn *websocket.Conn if conn, e = rl.upgrader.Upgrade(w, r, nil); log.Fail(e) { - rl.E.F("failed to upgrade websocket: %v\n", e) + rl.E.F("failed to upgrade websocket: %v", e) return } rl.clients.Store(conn, struct{}{}) @@ -109,7 +109,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { websocket.CloseNoStatusReceived, // 1005 websocket.CloseAbnormalClosure, // 1006 ) { - rl.E.F("unexpected close error from %s: %v\n", r.Header.Get("X-Forwarded-For"), e) + rl.E.F("unexpected close error from %s: %v", r.Header.Get("X-Forwarded-For"), e) } return } @@ -267,7 +267,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { "use of closed network connection", ) { rl.E.F("error writing ping: %v; "+ - "closing websocket\n", e) + "closing websocket", e) } return }