mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-17 13:07:16 +02:00
more logs
This commit is contained in:
parent
e82196b6fa
commit
1303429ca5
8 changed files with 46 additions and 22 deletions
2
go.mod
2
go.mod
|
|
@ -69,6 +69,7 @@ require (
|
|||
github.com/lightningnetwork/lnd/ticker v1.1.0 // indirect
|
||||
github.com/lightningnetwork/lnd/tlv v1.0.3 // indirect
|
||||
github.com/lightningnetwork/lnd/tor v1.0.1 // indirect
|
||||
github.com/magefile/mage v1.9.0 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.5 // indirect
|
||||
github.com/miekg/dns v1.1.43 // indirect
|
||||
github.com/nbd-wtf/ln-decodepay v1.5.1 // indirect
|
||||
|
|
@ -80,6 +81,7 @@ require (
|
|||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/tidwall/rtred v0.1.2 // indirect
|
||||
github.com/tidwall/tinyqueue v0.1.1 // indirect
|
||||
go.elastic.co/ecslogrus v1.0.0 // indirect
|
||||
go.opentelemetry.io/otel v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v0.20.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v0.20.0 // indirect
|
||||
|
|
|
|||
5
go.sum
5
go.sum
|
|
@ -629,6 +629,8 @@ github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796/go.mod h1:3p7ZTf9V1s
|
|||
github.com/ltcsuite/ltcutil v0.0.0-20181217130922-17f3b04680b6/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=
|
||||
github.com/lunixbochs/vtclean v0.0.0-20160125035106-4fbf7632a2c6/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||
github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE=
|
||||
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/makiuchi-d/gozxing v0.0.2 h1:TGSCQRXd9QL1ze1G1JE9sZBMEr6/HLx7m5ADlLUgq7E=
|
||||
|
|
@ -850,6 +852,7 @@ github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRci
|
|||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.0/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
|
|
@ -911,6 +914,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
|
|||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec/go.mod h1:BZ1RAoRPbCxum9Grlv5aeksu2H8BiKehBYooU2LFiOQ=
|
||||
go.elastic.co/ecslogrus v1.0.0 h1:o1qvcCNaq+eyH804AuK6OOiUupLIXVDfYjDtSLPwukM=
|
||||
go.elastic.co/ecslogrus v1.0.0/go.mod h1:vMdpljurPbwu+iFmNc/HSWCkn1Fu/dYde1o/adaEczo=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package internal
|
|||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.elastic.co/ecslogrus"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"io"
|
||||
)
|
||||
|
|
@ -9,17 +10,11 @@ import (
|
|||
func init() {
|
||||
stdoutLogger := log.New()
|
||||
customFormatter := new(log.TextFormatter)
|
||||
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
|
||||
customFormatter.FullTimestamp = true
|
||||
stdoutLogger.SetFormatter(customFormatter)
|
||||
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.SetFormatter(&log.JSONFormatter{
|
||||
FieldMap: log.FieldMap{
|
||||
log.FieldKeyTime: "@timestamp",
|
||||
log.FieldKeyMsg: "message",
|
||||
},
|
||||
})
|
||||
log.SetFormatter(&ecslogrus.Formatter{})
|
||||
|
||||
log.SetOutput(io.MultiWriter(stdoutLogger.Out, &lumberjack.Logger{
|
||||
Filename: "out.log",
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ func (bot *TipBot) balanceHandler(ctx intercept.Context) (intercept.Context, err
|
|||
balance, err := bot.GetUserBalance(user)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"module": "api",
|
||||
"func": "PayInvoice",
|
||||
"module": "telegram",
|
||||
"func": "balanceHandler",
|
||||
"path": "/balance",
|
||||
"user": usrStr,
|
||||
"user_id": user.ID,
|
||||
|
|
@ -48,8 +48,8 @@ func (bot *TipBot) balanceHandler(ctx intercept.Context) (intercept.Context, err
|
|||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"module": "api",
|
||||
"func": "PayInvoice",
|
||||
"module": "telegram",
|
||||
"func": "balanceHandler",
|
||||
"path": "/balance",
|
||||
"amount": balance,
|
||||
"user": usrStr,
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ func (bot TipBot) logMessageInterceptor(ctx intercept.Context) (intercept.Contex
|
|||
"module": "telegram",
|
||||
"func": "logMessageInterceptor",
|
||||
"path": ctx.Message().Text,
|
||||
"user_id": GetUserStr(ctx.Message().Sender),
|
||||
"user": GetUserStr(ctx.Message().Sender),
|
||||
"data": logString,
|
||||
"telegram_id": ctx.Sender().ID}).Infof("intercepting message")
|
||||
} else if ctx.Message().Photo != nil {
|
||||
|
|
@ -216,7 +216,7 @@ func (bot TipBot) logMessageInterceptor(ctx intercept.Context) (intercept.Contex
|
|||
"module": "telegram",
|
||||
"func": "logMessageInterceptor",
|
||||
"path": ctx.Message().Text,
|
||||
"user_id": GetUserStr(ctx.Message().Sender),
|
||||
"user": GetUserStr(ctx.Message().Sender),
|
||||
"data": fmt.Sprintf("[%s:%d %s:%d] %s", ctx.Message().Chat.Title, ctx.Message().Chat.ID, GetUserStr(ctx.Message().Sender), ctx.Message().Sender.ID, photoTag),
|
||||
"telegram_id": ctx.Sender().ID}).Infof("intercepting photo message")
|
||||
}
|
||||
|
|
@ -226,7 +226,7 @@ func (bot TipBot) logMessageInterceptor(ctx intercept.Context) (intercept.Contex
|
|||
"module": "telegram",
|
||||
"func": "logMessageInterceptor",
|
||||
"path": ctx.Message().Text,
|
||||
"user_id": GetUserStr(ctx.Message().Sender),
|
||||
"user": GetUserStr(ctx.Message().Sender),
|
||||
"data": fmt.Sprintf("[Callback %s:%d] Data: %s", GetUserStr(ctx.Callback().Sender), ctx.Callback().Sender.ID, ctx.Callback().Data),
|
||||
"telegram_id": ctx.Sender().ID}).Infof("intercepting callback")
|
||||
return ctx, nil
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ func (bot *TipBot) invoiceHandler(ctx intercept.Context) (intercept.Context, err
|
|||
|
||||
logfields := log.Fields{
|
||||
"module": "telegram",
|
||||
"func": "invoiceHandler",
|
||||
"path": "/invoice",
|
||||
"user": GetUserStr(user.Telegram),
|
||||
"user_id": user.ID,
|
||||
|
|
@ -159,7 +160,7 @@ func (bot *TipBot) invoiceHandler(ctx intercept.Context) (intercept.Context, err
|
|||
log.Errorln(errmsg)
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
logfields["invoice"] = invoice.PaymentRequest
|
||||
// create qr code
|
||||
qr, err := qrcode.Encode(invoice.PaymentRequest, qrcode.Medium, 256)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -200,7 +200,16 @@ func (bot *TipBot) confirmPayHandler(ctx intercept.Context) (intercept.Context,
|
|||
},
|
||||
)
|
||||
|
||||
log.Infof("[/pay] Attempting %s's invoice %s (%d sat)", userStr, payData.ID, payData.Amount)
|
||||
log.WithFields(log.Fields{
|
||||
"module": "telegram",
|
||||
"func": "confirmPayHandler",
|
||||
"user": userStr,
|
||||
"user_id": user.ID,
|
||||
"telegram_id": user.Telegram.ID,
|
||||
"path": "/pay",
|
||||
"data": payData.ID,
|
||||
"amount": payData.Amount,
|
||||
"wallet_id": user.Wallet.ID}).Infof("Attempting invoice payment")
|
||||
// pay invoice
|
||||
invoice, err := user.Wallet.Pay(lnbits.PaymentParams{Out: true, Bolt11: invoiceString}, bot.Client)
|
||||
if err != nil {
|
||||
|
|
@ -236,11 +245,15 @@ func (bot *TipBot) confirmPayHandler(ctx intercept.Context) (intercept.Context,
|
|||
bot.tryEditMessage(ctx.Message(), fmt.Sprintf(i18n.Translate(payData.LanguageCode, "invoicePublicPaidMessage"), userStr), &tb.ReplyMarkup{})
|
||||
}
|
||||
log.WithFields(log.Fields{
|
||||
"module": "telegram",
|
||||
"func": "acceptInlineTipjarHandler",
|
||||
"user": GetUserStr(user.Telegram),
|
||||
"user_id": user.ID,
|
||||
"wallet_id": user.Wallet.ID}).Infof("[⚡️ pay] User %s paid invoice %s (%d sat)", userStr, payData.ID, payData.Amount)
|
||||
"module": "telegram",
|
||||
"func": "confirmPayHandler",
|
||||
"user": userStr,
|
||||
"user_id": user.ID,
|
||||
"telegram_id": user.Telegram.ID,
|
||||
"path": "⚡️ pay",
|
||||
"data": payData.ID,
|
||||
"amount": payData.Amount,
|
||||
"wallet_id": user.Wallet.ID}).Infof("User paid invoice")
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,15 @@ func (bot *TipBot) GetUserBalance(user *lnbits.User) (amount int64, err error) {
|
|||
}
|
||||
// msat to sat
|
||||
amount = int64(wallet.Balance) / 1000
|
||||
log.Debugf("[GetUserBalance] %s's balance: %d sat\n", GetUserStr(user.Telegram), amount)
|
||||
log.WithFields(log.Fields{
|
||||
"module": "telegram",
|
||||
"func": "GetUserBalance",
|
||||
"user": GetUserStr(user.Telegram),
|
||||
"user_id": user.ID,
|
||||
"wallet_id": user.Wallet.ID,
|
||||
"telegram_id": user.Telegram.ID,
|
||||
"amount": amount},
|
||||
).Debugf("updated user balance")
|
||||
|
||||
// update user balance in cache
|
||||
bot.Cache.Set(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue