Skip to content

Commit

Permalink
fix: replace old logs with new logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Primexz committed May 5, 2024
1 parent 80a3384 commit 4c17321
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
14 changes: 10 additions & 4 deletions kraken/kraken_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"strconv"
"strings"

"github.com/aopoltorzhicky/go_kraken/rest"
"github.com/primexz/KrakenDCA/config"
"github.com/primexz/KrakenDCA/logger"
"github.com/primexz/KrakenDCA/notification"
)

var log *logger.Logger

func init() {
log = logger.NewLogger("kraken_api")
}

type KrakenSpread struct {
Error []interface{} `json:"error"`
Result map[string]interface{} `json:"result"`
Expand Down Expand Up @@ -55,18 +61,18 @@ func BuyBtc() {

response, err := getApi().AddOrder("xbt"+strings.ToLower(currency), "buy", "market", config.KrakenOrderSize, nil)
if err != nil {
log.Println("Failed to buy btc", err.Error())
log.Error("Failed to buy btc", err.Error())
return
}

fiatPrice, err := GetCurrentBtcFiatPrice()
if err != nil {
log.Println("Failed to get current btc price", err.Error())
log.Error("Failed to get current btc price", err.Error())
}

notification.SendPushNotification("BTC bought", fmt.Sprintf("Description: %s\nPrice: %f %s", response.Description.Info, fiatPrice, currency))

log.Println("Successfully bought btc ->", response.Description.Info, response.Description.Price)
log.Info("Successfully bought btc ->", response.Description.Info, response.Description.Price)
}

func getApi() *rest.Kraken {
Expand Down
17 changes: 12 additions & 5 deletions notification/gotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ package notification
import (
"bytes"
"encoding/json"
"log"
"net/http"
"net/url"
"os"

"github.com/primexz/KrakenDCA/logger"
)

var log *logger.Logger

func init() {
log = logger.NewLogger("gotify")
}

type GotifyMessage struct {
Title string `json:"title"`
Message string `json:"message"`
Expand All @@ -20,7 +27,7 @@ func SendPushNotification(title string, messageText string) {
rawUrl := os.Getenv("GOTIFY_URL")

if appToken == "" || rawUrl == "" {
log.Println("Skip sending push notification, not configured")
log.Debug("Skip sending push notification, not configured")
return
}

Expand All @@ -42,17 +49,17 @@ func SendPushNotification(title string, messageText string) {

bodyBytes, err := json.Marshal(message)
if err != nil {
log.Println(err)
log.Error(err)
}

reader := bytes.NewReader(bodyBytes)
rsp, err := http.Post(reqUrl.String(), "application/json", reader)

if err != nil {
log.Println("failed to send push notification", err)
log.Error("failed to send push notification", err)
}

if rsp.StatusCode != 200 {
log.Println("failed to send push notification, status code", rsp.StatusCode)
log.Error("failed to send push notification, status code", rsp.StatusCode)
}
}

0 comments on commit 4c17321

Please sign in to comment.