mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-19 10:36:42 +01:00
a pluggable logging interface and more debug logging.
This commit is contained in:
11
relay.go
11
relay.go
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -120,7 +119,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
||||
case <-ticker.C:
|
||||
err := conn.socket.WriteMessage(websocket.PingMessage, nil)
|
||||
if err != nil {
|
||||
log.Printf("error writing ping: %v; closing websocket", err)
|
||||
InfoLogger.Printf("{%s} error writing ping: %v; closing websocket", r.URL, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -188,7 +187,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
||||
var subId string
|
||||
json.Unmarshal(jsonMessage[1], &subId)
|
||||
if subscription, ok := r.subscriptions.Load(subId); !ok {
|
||||
log.Printf("no subscription with id '%s'\n", subId)
|
||||
InfoLogger.Printf("{%s} no subscription with id '%s'\n", r.URL, subId)
|
||||
continue
|
||||
} else {
|
||||
func() {
|
||||
@@ -198,7 +197,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
||||
|
||||
// check if the event matches the desired filter, ignore otherwise
|
||||
if !subscription.Filters.Match(&event) {
|
||||
log.Printf("filter does not match (%s): %v ~ %v\n", r.URL, subscription.Filters[0], event)
|
||||
InfoLogger.Printf("{%s} filter does not match: %v ~ %v\n", r.URL, subscription.Filters[0], event)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -215,7 +214,7 @@ func (r *Relay) Connect(ctx context.Context) error {
|
||||
if err != nil {
|
||||
errmsg = err.Error()
|
||||
}
|
||||
log.Printf("bad signature: %s\n", errmsg)
|
||||
InfoLogger.Printf("{%s} bad signature: %s\n", r.URL, errmsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -250,6 +249,8 @@ func (r *Relay) Connect(ctx context.Context) error {
|
||||
json.Unmarshal(jsonMessage[3], &msg)
|
||||
}
|
||||
|
||||
DebugLogger.Printf("{%s} OK: %s %v %s\n", r.URL, eventId, ok, msg)
|
||||
|
||||
if okCallback, exist := r.okCallbacks.Load(eventId); exist {
|
||||
okCallback(ok, msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user