Skip to content

Commit

Permalink
Use file based logging with log rotation
Browse files Browse the repository at this point in the history
file based logging might make it easier to load logs for debugging from the UI
  • Loading branch information
bumi committed Jan 20, 2024
1 parent 7e23cd2 commit a1e1f12
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
28 changes: 26 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a1e1f12

Please sign in to comment.