Skip to content

Commit

Permalink
Use slog
Browse files Browse the repository at this point in the history
  • Loading branch information
whywaita committed Feb 5, 2024
1 parent c237f63 commit 38dfa29
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 AS builder
FROM golang:1.21 AS builder

WORKDIR /go/src/github.com/whywaita/shoes-lxd-multi/server

Expand Down
2 changes: 1 addition & 1 deletion server/pkg/api/server_add_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func getResources(targetLXDHosts []lxdclient.LXDHost) ([]targetHost, error) {
t := t
eg.Go(func() error {
l := slog.With("host", t.HostConfig.LxdHost)
resources, err := lxdclient.GetResource(t.HostConfig)
resources, err := lxdclient.GetResource(t.HostConfig, l)
if err != nil {
l.Warn("failed to get resource", "err", err.Error())
return nil
Expand Down
5 changes: 3 additions & 2 deletions server/pkg/lxdclient/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"log/slog"
"strconv"

"github.com/whywaita/shoes-lxd-multi/server/pkg/config"
Expand All @@ -27,7 +28,7 @@ func GetCPUOverCommitPercent(in Resource) uint64 {
}

// GetResource get Resource
func GetResource(hostConfig config.HostConfig) (*Resource, error) {
func GetResource(hostConfig config.HostConfig, logger *slog.Logger) (*Resource, error) {
status, err := GetStatusCache(hostConfig.LxdHost)
if err == nil {
// found from cache
Expand All @@ -37,7 +38,7 @@ func GetResource(hostConfig config.HostConfig) (*Resource, error) {
return nil, fmt.Errorf("failed to get status from cache: %w", err)
}

log.Printf("failed to get status from cache, so scrape from lxd")
logger.Warn("failed to get status from cache, so scrape from lxd")

client, err := ConnectLXDWithTimeout(hostConfig.LxdHost, hostConfig.LxdClientCert, hostConfig.LxdClientKey)
if err != nil {
Expand Down

0 comments on commit 38dfa29

Please sign in to comment.