Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use file based logging with log rotation #227

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.env.local
*.db
*.macaroon
*.log
node_modules
nostr-wallet-connect
nwc.db
Expand Down
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 @@ -2,7 +2,7 @@

go 1.21

toolchain go1.21.1

Check failure on line 5 in go.mod

View workflow job for this annotation

GitHub Actions / build

unknown directive: toolchain

Check failure on line 5 in go.mod

View workflow job for this annotation

GitHub Actions / build

unknown directive: toolchain

require (
github.com/breez/breez-sdk-go v0.2.10
Expand All @@ -13,6 +13,7 @@
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
29 changes: 27 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)

fileLoggerHook, err := lumberjackrus.NewHook(
&lumberjackrus.LogFile{
Filename: "nwc.general.log",
rolznz marked this conversation as resolved.
Show resolved Hide resolved
},
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(fileLoggerHook)
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 Expand Up @@ -231,6 +255,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
Expand Down
4 changes: 4 additions & 0 deletions models/db/db.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package db

import "time"

type Config struct {
ID int // primary key, always 1
LNBackendType string `envconfig:"LN_BACKEND_TYPE"`
Expand All @@ -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
}
Loading