From 390a02a2d8e34c391f463d42c7a3668a41d0336c Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 2 Aug 2024 21:07:57 +0700 Subject: [PATCH 1/2] chore: log events by default --- .env.example | 6 +++--- config/models.go | 2 +- service/start.go | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 664baa08..a4239df8 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,6 @@ +# only enable event logging in production +LOG_EVENTS=false + #WORK_DIR=.data #DATABASE_URI=nwc.db #NOSTR_PRIVKEY= @@ -8,9 +11,6 @@ #FRONTEND_URL=http://localhost:5173 #AUTO_LINK_ALBY_ACCOUNT=false -# set LDK_GOSSIP_SOURCE as empty to not use RGS -#LDK_GOSSIP_SOURCE= - # Alby OAuth configuration #ALBY_OAUTH_CLIENT_SECRET= #ALBY_OAUTH_CLIENT_ID= diff --git a/config/models.go b/config/models.go index 8df1ad43..13277840 100644 --- a/config/models.go +++ b/config/models.go @@ -35,7 +35,7 @@ type AppConfig struct { AlbyOAuthAuthUrl string `envconfig:"ALBY_OAUTH_AUTH_URL" default:"https://getalby.com/oauth"` BaseUrl string `envconfig:"BASE_URL" default:"http://localhost:8080"` FrontendUrl string `envconfig:"FRONTEND_URL"` - LogEvents bool `envconfig:"LOG_EVENTS" default:"false"` + LogEvents bool `envconfig:"LOG_EVENTS" default:"true"` AutoLinkAlbyAccount bool `envconfig:"AUTO_LINK_ALBY_ACCOUNT" default:"true"` PhoenixdAddress string `envconfig:"PHOENIXD_ADDRESS"` PhoenixdAuthorization string `envconfig:"PHOENIXD_AUTHORIZATION"` diff --git a/service/start.go b/service/start.go index 7b27f1c1..457b7468 100644 --- a/service/start.go +++ b/service/start.go @@ -202,8 +202,9 @@ func (svc *service) launchLNBackend(ctx context.Context, encryptionKey string) e if err != nil { logger.Logger.WithError(err).Error("Failed to fetch node info") } - if info != nil && info.Pubkey != "" { + if info != nil { svc.eventPublisher.SetGlobalProperty("node_id", info.Pubkey) + svc.eventPublisher.SetGlobalProperty("network", info.Network) } svc.eventPublisher.Publish(&events.Event{ From abec373b63e8b3ba038668c654692d649e2f47ab Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 2 Aug 2024 21:15:15 +0700 Subject: [PATCH 2/2] chore: log global properties --- events/events.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/events/events.go b/events/events.go index 8bb4a5ad..513f866a 100644 --- a/events/events.go +++ b/events/events.go @@ -23,21 +23,21 @@ func NewEventPublisher() *eventPublisher { return eventPublisher } -func (el *eventPublisher) RegisterSubscriber(listener EventSubscriber) { - el.subscriberMtx.Lock() - defer el.subscriberMtx.Unlock() - el.listeners = append(el.listeners, listener) +func (ep *eventPublisher) RegisterSubscriber(listener EventSubscriber) { + ep.subscriberMtx.Lock() + defer ep.subscriberMtx.Unlock() + ep.listeners = append(ep.listeners, listener) } -func (el *eventPublisher) RemoveSubscriber(listenerToRemove EventSubscriber) { - el.subscriberMtx.Lock() - defer el.subscriberMtx.Unlock() +func (ep *eventPublisher) RemoveSubscriber(listenerToRemove EventSubscriber) { + ep.subscriberMtx.Lock() + defer ep.subscriberMtx.Unlock() - for i, listener := range el.listeners { + for i, listener := range ep.listeners { // delete the listener from the listeners array if listener == listenerToRemove { - el.listeners[i] = el.listeners[len(el.listeners)-1] - el.listeners = slices.Delete(el.listeners, len(el.listeners)-1, len(el.listeners)) + ep.listeners[i] = ep.listeners[len(ep.listeners)-1] + ep.listeners = slices.Delete(ep.listeners, len(ep.listeners)-1, len(ep.listeners)) break } } @@ -46,7 +46,7 @@ func (el *eventPublisher) RemoveSubscriber(listenerToRemove EventSubscriber) { func (ep *eventPublisher) Publish(event *Event) { ep.subscriberMtx.Lock() defer ep.subscriberMtx.Unlock() - logger.Logger.WithFields(logrus.Fields{"event": event}).Info("Publishing event") + logger.Logger.WithFields(logrus.Fields{"event": event, "global": ep.globalProperties}).Info("Publishing event") for _, listener := range ep.listeners { // events are consumed in sequence as some listeners depend on earlier consumers // (e.g. NIP-47 notifier depends on transactions service updating transactions) @@ -54,6 +54,6 @@ func (ep *eventPublisher) Publish(event *Event) { } } -func (el *eventPublisher) SetGlobalProperty(key string, value interface{}) { - el.globalProperties[key] = value +func (ep *eventPublisher) SetGlobalProperty(key string, value interface{}) { + ep.globalProperties[key] = value }