json logging

This commit is contained in:
kiwiidb
2023-09-22 17:12:49 +02:00
parent 4ff3ebf79b
commit 8bee438653
11 changed files with 166 additions and 26 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/getAlby/lndhub.go/lnd"
"github.com/getsentry/sentry-go"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"github.com/lightningnetwork/lnd/lnrpc"
)
@@ -83,7 +84,13 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
ok, err := controller.svc.BalanceCheck(c.Request().Context(), lnPayReq, userID)
if err != nil {
c.Logger().Errorf("Failed to check balance user_id: %v error: %v", userID, err)
c.Logger().Errorj(
log.JSON{
"message": "failed to check balance",
"error": err,
"lndhub_user_id": userID,
},
)
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
}
if !ok {
@@ -92,7 +99,13 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
}
invoice, err := controller.svc.AddOutgoingInvoice(c.Request().Context(), userID, "", lnPayReq)
if err != nil {
c.Logger().Errorf("Error saving invoice user_id: %v error: %v", userID, err)
c.Logger().Errorj(
log.JSON{
"message": "failed to add invoice",
"error": err,
"lndhub_user_id": userID,
},
)
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
}
if _, err := hex.DecodeString(invoice.DestinationPubkeyHex); err != nil || len(invoice.DestinationPubkeyHex) != common.DestinationPubkeyHexSize {
@@ -103,7 +116,13 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
for key, value := range reqBody.CustomRecords {
intKey, err := strconv.Atoi(key)
if err != nil {
c.Logger().Errorf("Invalid custom records user_id: %v error: %v", userID, err)
c.Logger().Errorj(
log.JSON{
"message": "invalid custom records",
"error": err,
"lndhub_user_id": userID,
},
)
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
}
invoice.DestinationCustomRecords[uint64(intKey)] = []byte(value)