From cfaebd911ca883a324a6e4c142f8f13b518a98d8 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 19 Jan 2024 23:34:58 +0700 Subject: [PATCH 1/5] chore: error handling --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index ed1551ee..ad1386bd 100644 --- a/main.go +++ b/main.go @@ -231,6 +231,7 @@ func (svc *Service) launchLNBackend() error { svc.Logger.Fatalf("Unsupported LNBackendType: %v", dbConfig.LNBackendType) } if err != nil { + svc.Logger.Errorf("Failed to launch LN backend: %v", err) return err } svc.lnClient = lnClient From a1e1f1251a08e5e50abe70d7d8fc83389faa8206 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sat, 20 Jan 2024 01:29:25 +0100 Subject: [PATCH 2/5] Use file based logging with log rotation file based logging might make it easier to load logs for debugging from the UI --- README.md | 2 ++ go.mod | 1 + go.sum | 2 ++ main.go | 28 ++++++++++++++++++++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 64356945..c71d5ed9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Connect applications like [Damus](https://damus.io/) or [Amethyst](https://linkt ### Requirements +- Go 1.21 or higher + The application has no runtime dependencies. (simple Go executable). As data storage SQLite is used. diff --git a/go.mod b/go.mod index 4944fe64..2570c0c7 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/labstack/echo/v4 v4.10.2 github.com/nbd-wtf/go-nostr v0.25.5 github.com/nbd-wtf/ln-decodepay v1.11.1 + github.com/orandin/lumberjackrus v1.0.1 github.com/stretchr/testify v1.8.2 github.com/wailsapp/wails/v2 v2.7.1 google.golang.org/grpc v1.53.0 diff --git a/go.sum b/go.sum index 959b514d..d7501825 100644 --- a/go.sum +++ b/go.sum @@ -656,6 +656,8 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/orandin/lumberjackrus v1.0.1 h1:7ysDQ0MHD79zIFN9/EiDHjUcgopNi5ehtxFDy8rUkWo= +github.com/orandin/lumberjackrus v1.0.1/go.mod h1:xYLt6H8W93pKnQgUQaxsApS0Eb4BwHLOkxk5DVzf5H0= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pierrec/lz4/v4 v4.0.3/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= diff --git a/main.go b/main.go index ed1551ee..f55884b3 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "github.com/kelseyhightower/envconfig" "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip19" + "github.com/orandin/lumberjackrus" log "github.com/sirupsen/logrus" "gorm.io/gorm" ) @@ -93,11 +94,34 @@ func NewService(ctx context.Context) *Service { logger := log.New() logger.SetFormatter(&log.JSONFormatter{}) - logger.SetOutput(os.Stdout) logger.SetLevel(log.InfoLevel) + + hook, err := lumberjackrus.NewHook( + &lumberjackrus.LogFile{ + Filename: "nwc.general.log", + }, + log.InfoLevel, + &log.JSONFormatter{}, + &lumberjackrus.LogFileOpts{ + log.InfoLevel: &lumberjackrus.LogFile{ + Filename: "./log/nwc-info.log", + MaxAge: 1, + MaxBackups: 2, + }, + log.ErrorLevel: &lumberjackrus.LogFile{ + Filename: "./log/nwc-error.log", + MaxAge: 1, + MaxBackups: 2, + }, + }, + ) + if err != nil { + log.Fatalf("Error log setup: %v", err) + } + logger.AddHook(hook) svc.Logger = logger - logger.Infof("Starting nostr-wallet-connect. npub: %s hex: %s", npub, identityPubkey) + svc.Logger.Infof("Starting nostr-wallet-connect. npub: %s hex: %s", npub, identityPubkey) err = svc.launchLNBackend() if err != nil { From a16b810970e87b9f39d24024a49f897f54aa288d Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Mon, 22 Jan 2024 14:08:03 +0700 Subject: [PATCH 3/5] fix: add createdAt and updatedAt to config table struct --- models/db/db.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/db/db.go b/models/db/db.go index f279a204..5885d944 100644 --- a/models/db/db.go +++ b/models/db/db.go @@ -1,5 +1,7 @@ package db +import "time" + type Config struct { ID int // primary key, always 1 LNBackendType string `envconfig:"LN_BACKEND_TYPE"` @@ -10,4 +12,6 @@ type Config struct { BreezAPIKey string `envconfig:"BREEZ_API_KEY"` GreenlightInviteCode string `envconfig:"GREENLIGHT_INVITE_CODE"` NostrSecretKey string `envconfig:"NOSTR_PRIVKEY"` + CreatedAt time.Time + UpdatedAt time.Time } From d4bf679e2a5add61684f322510f6d9cee8e8461a Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Mon, 22 Jan 2024 14:21:32 +0700 Subject: [PATCH 4/5] chore: add log files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1e86a272..3459a978 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .env.local *.db *.macaroon +*.log node_modules nostr-wallet-connect nwc.db From c8374da0e9bdc82551b92cfd8fe6950829d1306f Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Mon, 22 Jan 2024 14:22:03 +0700 Subject: [PATCH 5/5] chore: rename --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index dafc0d88..55eb2b9a 100644 --- a/main.go +++ b/main.go @@ -96,7 +96,7 @@ func NewService(ctx context.Context) *Service { logger.SetFormatter(&log.JSONFormatter{}) logger.SetLevel(log.InfoLevel) - hook, err := lumberjackrus.NewHook( + fileLoggerHook, err := lumberjackrus.NewHook( &lumberjackrus.LogFile{ Filename: "nwc.general.log", }, @@ -118,7 +118,7 @@ func NewService(ctx context.Context) *Service { if err != nil { log.Fatalf("Error log setup: %v", err) } - logger.AddHook(hook) + logger.AddHook(fileLoggerHook) svc.Logger = logger svc.Logger.Infof("Starting nostr-wallet-connect. npub: %s hex: %s", npub, identityPubkey)