Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to using slog for logging #4

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
module github.com/tessellated-io/healthchecks

go 1.21
go 1.21.0

require github.com/tessellated-io/pickaxe v1.0.11
toolchain go1.22.6

require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/rs/zerolog v1.29.1 // indirect
golang.org/x/sys v0.10.0 // indirect
)
require github.com/tessellated-io/pickaxe v1.2.0

require github.com/dpotapov/slogpfx v0.0.0-20230917063348-41a73c95c536 // indirect
33 changes: 12 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
github.com/tessellated-io/pickaxe v1.0.11 h1:gaQVdYh+DMSE1tXA44JCunwmQnXeplblp2HQFowiNaE=
github.com/tessellated-io/pickaxe v1.0.11/go.mod h1:wO7zNwLt2PbwH5C9j+p/KM+4I6K4zXY7rrq1567CPJE=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dpotapov/slogpfx v0.0.0-20230917063348-41a73c95c536 h1:3ZUyGIhpbUJVL3nwGRJO/DH1GRNb3qhKOteP1tMwFrA=
github.com/dpotapov/slogpfx v0.0.0-20230917063348-41a73c95c536/go.mod h1:L9xGyDDA8E/83ucQSIKU/ZU3YfS3BzhyynT0ykxJGCk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tessellated-io/pickaxe v1.2.0 h1:0Jm06yY+hgVAfjxhxdCPK6/u4+vWkJhApD5r6q756M8=
github.com/tessellated-io/pickaxe v1.2.0/go.mod h1:eh7qys33qMgVNfcuPyb3AlvRKiHRFu0Z456jeKVQV6E=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 7 additions & 5 deletions health/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type healthClient struct {
var _ HealthClient = (*healthClient)(nil)

func NewHealthClient(logger *log.Logger, apiKey, pingKey string, createNewChecks bool, timeoutSeconds, gracePeriodSeconds int) HealthClient {
prefixedLogger := logger.ApplyPrefix(" [HEALTHCHECKS] 🩺")
prefixedLogger := logger.ApplyPrefix("[HEALTHCHECKS] 🩺")

client := &http.Client{
Timeout: 10 * time.Second,
Expand All @@ -62,7 +62,8 @@ func NewHealthClient(logger *log.Logger, apiKey, pingKey string, createNewChecks
// HealthCheck Interface

func (hc *healthClient) SendSuccess(slug string) error {
hc.logger.Info().Str("slug", slug).Msg("sending success")
logger := hc.logger.With("slug", slug)
logger.Info("sending success")

if hc.createNewChecks {
err := hc.UpsertCheck(slug)
Expand All @@ -83,13 +84,14 @@ func (hc *healthClient) SendSuccess(slug string) error {
if err != nil {
return err
}
hc.logger.Debug().Str("response", string(body)).Int("status", resp.StatusCode).Str("slug", slug).Msg("got response from success call")
logger.Debug("got response from success call", "response", string(body), "status", resp.StatusCode)

return nil
}

func (hc *healthClient) SendFailure(slug string) error {
hc.logger.Info().Str("slug", slug).Msg("sending failure")
logger := hc.logger.With("slug", slug)
logger.Info("sending failure")

if hc.createNewChecks {
err := hc.UpsertCheck(slug)
Expand All @@ -109,7 +111,7 @@ func (hc *healthClient) SendFailure(slug string) error {
if err != nil {
return err
}
hc.logger.Debug().Str("response", string(body)).Int("status", resp.StatusCode).Str("slug", slug).Msg("got response from failure call")
logger.Debug("got response from failure call", "response", string(body), "status", resp.StatusCode)

return nil
}
Expand Down
Loading