Skip to content

Commit

Permalink
Update usages of log. to the slog compatible logger
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Mar 17, 2024
1 parent ca1b6ca commit 4f895b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 0 additions & 2 deletions pkg/util/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package util

import (
"fmt"
"log"

"github.com/chia-network/go-chia-libs/pkg/types"
)
Expand All @@ -13,7 +12,6 @@ func FormatBytes(bytes types.Uint128) string {
base := uint64(1024)

value := bytes.Div64(base)
log.Printf("%s %s\n", value.String(), "KiB")
for _, label := range labels {
if value.FitsInUint64() {
valueUint64 := float64(value.Uint64()) / float64(base)
Expand Down
15 changes: 7 additions & 8 deletions pkg/websocketclient/websocketclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"log/slog"
"net/http"
"net/url"
Expand Down Expand Up @@ -322,14 +321,14 @@ func (c *WebsocketClient) reconnectLoop() {
handler()
}
for {
log.Println("Trying to reconnect...")
c.logger.Info("Trying to reconnect...")
err := c.ensureConnection()
if err == nil {
log.Println("Reconnected!")
c.logger.Info("Reconnected!")
for topic := range c.subscriptions {
err = c.doSubscribe(topic)
if err != nil {
log.Printf("Error subscribing to topic %s: %s\n", topic, err.Error())
c.logger.Error("Error subscribing to topic", "topic", topic, "error", err.Error())
}
}
for _, handler := range c.reconnectHandlers {
Expand All @@ -338,7 +337,7 @@ func (c *WebsocketClient) reconnectLoop() {
return
}

log.Printf("Unable to reconnect: %s\n", err.Error())
c.logger.Error("Unable to reconnect", "error", err.Error())
time.Sleep(5 * time.Second)
}
}
Expand Down Expand Up @@ -405,12 +404,12 @@ func (c *WebsocketClient) listen() {
for {
_, message, err := c.conn.ReadMessage()
if err != nil {
log.Printf("Error reading message on chia websocket: %s\n", err.Error())
c.logger.Error("Error reading message on chia websocket", "error", err.Error())
if _, isCloseErr := err.(*websocket.CloseError); !isCloseErr {
log.Println("Chia websocket sent close message, attempting to close connection...")
c.logger.Debug("Chia websocket sent close message, attempting to close connection...")
closeConnErr := c.conn.Close()
if closeConnErr != nil {
log.Printf("Error closing chia websocket connection: %s\n", closeConnErr.Error())
c.logger.Error("Error closing chia websocket connection", "error", closeConnErr.Error())
}
}
c.conn = nil
Expand Down

0 comments on commit 4f895b4

Please sign in to comment.