Skip to content

Commit 5ec320c

Browse files
committed
chore: use new httplog module
1 parent be09023 commit 5ec320c

6 files changed

Lines changed: 16 additions & 131 deletions

File tree

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module github.com/UpCloudLtd/upcloud-go-api/v8
22

3-
go 1.24.13
3+
go 1.25
44

55
require (
6+
github.com/UpCloudLtd/httplog v0.0.0-20260624214043-23b0cab8e085
67
github.com/davecgh/go-spew v1.1.1
78
github.com/dnaeon/go-vcr v1.2.0
89
github.com/stretchr/testify v1.11.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/UpCloudLtd/httplog v0.0.0-20260624214043-23b0cab8e085 h1:WKK9DZI0ZQikQjhHk+/X2HWKxFrENOvseaDysZE8nPs=
2+
github.com/UpCloudLtd/httplog v0.0.0-20260624214043-23b0cab8e085/go.mod h1:79ZjkJrYkl540hQ5Fy7XkRfR7109HGMTzHdVEkynTqw=
13
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
24
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
35
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

upcloud/client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strings"
1515
"time"
1616

17-
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/client/logging"
17+
"github.com/UpCloudLtd/httplog"
1818
)
1919

2020
const (
@@ -35,7 +35,7 @@ type config struct {
3535
token string
3636
baseURL string
3737
httpClient *http.Client
38-
logger *logging.Logger
38+
logger *httplog.Logger
3939
}
4040

4141
// Client represents an API client
@@ -309,9 +309,9 @@ func WithTimeout(timeout time.Duration) ConfigFn {
309309
}
310310

311311
// WithLogger configures logging function that logs requests and responses
312-
func WithLogger(logger logging.LogFn) ConfigFn {
312+
func WithLogger(logger httplog.LogFn) ConfigFn {
313313
return func(c *config) {
314-
c.logger = logging.NewLogger(logger)
314+
c.logger = httplog.NewLogger(logger)
315315
}
316316
}
317317

upcloud/client/client_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"testing"
1515
"time"
1616

17-
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/client/logging"
17+
"github.com/UpCloudLtd/httplog"
1818
"github.com/stretchr/testify/assert"
1919
"github.com/stretchr/testify/require"
2020
)
@@ -220,7 +220,7 @@ func TestClientGetContextDeadline(t *testing.T) {
220220
require.True(t, errors.Is(err, context.DeadlineExceeded))
221221
}
222222

223-
func getTestLogFn(w io.Writer) logging.LogFn {
223+
func getTestLogFn(w io.Writer) httplog.LogFn {
224224
return slog.New(slog.NewJSONHandler(w, &slog.HandlerOptions{
225225
Level: slog.LevelDebug,
226226
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
@@ -263,8 +263,8 @@ func TestClientRequestLogging(t *testing.T) {
263263
configFns: func(w io.Writer) []ConfigFn {
264264
return []ConfigFn{
265265
WithHTTPClient(&http.Client{
266-
Transport: &logging.LoggingTransport{
267-
Logger: logging.NewLogger(getTestLogFn(w)),
266+
Transport: &httplog.LoggingTransport{
267+
Logger: httplog.NewLogger(getTestLogFn(w)),
268268
},
269269
}),
270270
}
@@ -283,10 +283,10 @@ func TestClientRequestLogging(t *testing.T) {
283283
_, err = c.Post(context.TODO(), "/test", []byte(`{"name": "test"}`))
284284
require.NoError(t, err)
285285

286-
expected := fmt.Sprintf(`{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Sending request to UpCloud API","url":"http://server/1.3/test","method":"GET","headers":{"Accept":["application/json"],"Authorization":["Basic [REDACTED]"],"Content-Type":["application/json"],"User-Agent":["upcloud-go-api/%s"]},"body":""}
287-
{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Received response from UpCloud API","url":"http://server/1.3/test","status":"200 OK","headers":{"Content-Length":["38"],"Content-Type":["text/plain; charset=utf-8"],"Date":["Fri, 11 Oct 2024 23:58:00 GMT"]},"body":"{\n \"method\": \"GET\",\n \"path\": \"/1.3/test\"\n}"}
288-
{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Sending request to UpCloud API","url":"http://server/1.3/test","method":"POST","headers":{"Accept":["application/json"],"Authorization":["Basic [REDACTED]"],"Content-Type":["application/json"],"User-Agent":["upcloud-go-api/8.38.0"]},"body":"{\n \"name\": \"test\"\n}"}
289-
{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Received response from UpCloud API","url":"http://server/1.3/test","status":"200 OK","headers":{"Content-Length":["39"],"Content-Type":["text/plain; charset=utf-8"],"Date":["Fri, 11 Oct 2024 23:58:00 GMT"]},"body":"{\n \"method\": \"POST\",\n \"path\": \"/1.3/test\"\n}"}
286+
expected := fmt.Sprintf(`{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Sending request to 127.0.0.1","url":"http://server/1.3/test","method":"GET","headers":{"Accept":["application/json"],"Authorization":["Basic [REDACTED]"],"Content-Type":["application/json"],"User-Agent":["upcloud-go-api/%s"]},"body":""}
287+
{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Received response from 127.0.0.1","url":"http://server/1.3/test","status":"200 OK","headers":{"Content-Length":["38"],"Content-Type":["text/plain; charset=utf-8"],"Date":["Fri, 11 Oct 2024 23:58:00 GMT"]},"body":"{\n \"method\": \"GET\",\n \"path\": \"/1.3/test\"\n}"}
288+
{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Sending request to 127.0.0.1","url":"http://server/1.3/test","method":"POST","headers":{"Accept":["application/json"],"Authorization":["Basic [REDACTED]"],"Content-Type":["application/json"],"User-Agent":["upcloud-go-api/8.38.0"]},"body":"{\n \"name\": \"test\"\n}"}
289+
{"time":"2 Minutes to Midnight","level":"DEBUG","msg":"Received response from 127.0.0.1","url":"http://server/1.3/test","status":"200 OK","headers":{"Content-Length":["39"],"Content-Type":["text/plain; charset=utf-8"],"Date":["Fri, 11 Oct 2024 23:58:00 GMT"]},"body":"{\n \"method\": \"POST\",\n \"path\": \"/1.3/test\"\n}"}
290290
`, Version)
291291
assert.Equal(t, expected, output.String())
292292
})

upcloud/client/logging/logger.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

upcloud/client/logging/transport.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)