Skip to content

Commit

Permalink
feat!: introduce logger choice via slog
Browse files Browse the repository at this point in the history
Historically brokerapi has required use of the
[`lager`](https://github.com/cloudfoundry/lager) logger. In Go 1.21,
structured logging was introduced into the Go standard library via the
[`log/slog`](https://pkg.go.dev/log/slog) package, and `slog`
[compatability was added](cloudfoundry/lager@4bf4955)
to `lager`.

`brokerapi` has been modified to require a `slog` logger to be passed
rather than a `lager` logger. This allows users a choice of logger.
Users who still want to use lager can easily do that using the
lager/slog compatability:
```go
logger := lager.NewLogger(name)
brokerAPI := brokerapi.New(serviceBroker, slog.New(lager.NewHandler(logger)), credentials)
```

And users who want to use `slog` or an `slog`-compatible logger can do
that instead.

A key advantage is that `lager` is no longer a dependency of this
package, which simplifies package management for apps that use brokerapi
and other libraries which use `lager`.
  • Loading branch information
blgm committed Feb 5, 2024
1 parent 70c69f2 commit 3437960
Show file tree
Hide file tree
Showing 27 changed files with 357 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: [ 'stable', 'oldstable', '1.20' ]
version: [ 'stable', 'oldstable', '1.21' ]
name: Go ${{ matrix.version }}
outputs:
pr_number: ${{ github.event.number }}
Expand Down
10 changes: 5 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package brokerapi

import (
"log/slog"
"net/http"

"code.cloudfoundry.org/lager/v3"
"github.com/go-chi/chi/v5"
"github.com/pivotal-cf/brokerapi/v10/handlers"
)
Expand All @@ -28,19 +28,19 @@ type BrokerCredentials struct {
Password string
}

func New(serviceBroker ServiceBroker, logger lager.Logger, brokerCredentials BrokerCredentials) http.Handler {
func New(serviceBroker ServiceBroker, logger *slog.Logger, brokerCredentials BrokerCredentials) http.Handler {
return NewWithOptions(serviceBroker, logger, WithBrokerCredentials(brokerCredentials))
}

func NewWithCustomAuth(serviceBroker ServiceBroker, logger lager.Logger, authMiddleware middlewareFunc) http.Handler {
func NewWithCustomAuth(serviceBroker ServiceBroker, logger *slog.Logger, authMiddleware middlewareFunc) http.Handler {
return NewWithOptions(serviceBroker, logger, WithCustomAuth(authMiddleware))
}

func AttachRoutes(router chi.Router, serviceBroker ServiceBroker, logger lager.Logger) {
func AttachRoutes(router chi.Router, serviceBroker ServiceBroker, logger *slog.Logger) {
attachRoutes(router, serviceBroker, logger)
}

func attachRoutes(router chi.Router, serviceBroker ServiceBroker, logger lager.Logger) {
func attachRoutes(router chi.Router, serviceBroker ServiceBroker, logger *slog.Logger) {
apiHandler := handlers.NewApiHandler(serviceBroker, logger)
router.Get("/v2/catalog", apiHandler.Catalog)

Expand Down
8 changes: 4 additions & 4 deletions api_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package brokerapi

import (
"log/slog"
"net/http"

"code.cloudfoundry.org/lager/v3"
"github.com/go-chi/chi/v5"
"github.com/pivotal-cf/brokerapi/v10/auth"
"github.com/pivotal-cf/brokerapi/v10/domain"
Expand All @@ -30,11 +30,11 @@ type middlewareFunc func(http.Handler) http.Handler
type config struct {
router chi.Router
customRouter bool
logger lager.Logger
logger *slog.Logger
additionalMiddleware []middlewareFunc
}

func NewWithOptions(serviceBroker domain.ServiceBroker, logger lager.Logger, opts ...Option) http.Handler {
func NewWithOptions(serviceBroker domain.ServiceBroker, logger *slog.Logger, opts ...Option) http.Handler {
cfg := config{
router: chi.NewRouter(),
logger: logger,
Expand Down Expand Up @@ -95,7 +95,7 @@ func withDefaultMiddleware() Option {
return func(c *config) {
if !c.customRouter {
defaults := []middlewareFunc{
middlewares.APIVersionMiddleware{LoggerFactory: c.logger}.ValidateAPIVersionHdr,
middlewares.APIVersionMiddleware{Logger: c.logger}.ValidateAPIVersionHdr,
middlewares.AddCorrelationIDToContext,
middlewares.AddOriginatingIdentityToContext,
middlewares.AddInfoLocationToContext,
Expand Down
262 changes: 138 additions & 124 deletions api_test.go

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions domain/apiresponses/failure_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package apiresponses

import (
"fmt"
"log/slog"
"net/http"

"code.cloudfoundry.org/lager/v3"
"github.com/pivotal-cf/brokerapi/v10/internal/logutil"
)

// FailureResponse can be returned from any of the `ServiceBroker` interface methods
Expand Down Expand Up @@ -43,12 +44,10 @@ func (f *FailureResponse) ErrorResponse() interface{} {
}
}

// ValidatedStatusCode returns the HTTP response status code. If the code is not 4xx
// or 5xx, an InternalServerError will be returned instead.
func (f *FailureResponse) ValidatedStatusCode(logger lager.Logger) int {
func (f *FailureResponse) ValidatedStatusCode(prefix string, logger *slog.Logger) int {
if f.statusCode < 400 || 600 <= f.statusCode {
if logger != nil {
logger.Error("validating-status-code", fmt.Errorf("Invalid failure http response code: 600, expected 4xx or 5xx, returning internal server error: 500."))
logger.Error(logutil.Join(prefix, "validating-status-code"), slog.String("error", "Invalid failure http response code: 600, expected 4xx or 5xx, returning internal server error: 500."))
}
return http.StatusInternalServerError
}
Expand Down
20 changes: 9 additions & 11 deletions domain/apiresponses/failure_responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package apiresponses_test

import (
"errors"
"log/slog"
"net/http"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pivotal-cf/brokerapi/v10/domain/apiresponses"

"code.cloudfoundry.org/lager/v3"
"github.com/onsi/gomega/gbytes"
"github.com/pivotal-cf/brokerapi/v10/domain/apiresponses"
)

var _ = Describe("FailureResponse", func() {
Expand Down Expand Up @@ -47,7 +46,7 @@ var _ = Describe("FailureResponse", func() {
newError := failureResponse.AppendErrorMessage("and some more details")

Expect(newError.Error()).To(Equal("my error message and some more details"))
Expect(newError.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(newError.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
Expect(newError.LoggerAction()).To(Equal(failureResponse.LoggerAction()))

errorResponse, typeCast := newError.ErrorResponse().(apiresponses.ErrorResponse)
Expand All @@ -63,7 +62,7 @@ var _ = Describe("FailureResponse", func() {
newError := failureResponse.AppendErrorMessage("and some more details")

Expect(newError.Error()).To(Equal("my error message and some more details"))
Expect(newError.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(newError.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
Expect(newError.LoggerAction()).To(Equal(failureResponse.LoggerAction()))
Expect(newError.ErrorResponse()).To(Equal(failureResponse.ErrorResponse()))
})
Expand All @@ -72,26 +71,25 @@ var _ = Describe("FailureResponse", func() {
Describe("ValidatedStatusCode", func() {
It("returns the status code that was passed in", func() {
failureResponse := asFailureResponse(apiresponses.NewFailureResponse(errors.New("my error message"), http.StatusForbidden, "log-key"))
Expect(failureResponse.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(failureResponse.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
})

It("when error key is provided it returns the status code that was passed in", func() {
failureResponse := apiresponses.NewFailureResponseBuilder(errors.New("my error message"), http.StatusForbidden, "log-key").WithErrorKey("error key").Build()
Expect(failureResponse.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(failureResponse.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
})

Context("when the status code is invalid", func() {
It("returns 500", func() {
failureResponse := asFailureResponse(apiresponses.NewFailureResponse(errors.New("my error message"), 600, "log-key"))
Expect(failureResponse.ValidatedStatusCode(nil)).To(Equal(http.StatusInternalServerError))
Expect(failureResponse.ValidatedStatusCode("", nil)).To(Equal(http.StatusInternalServerError))
})

It("logs that the status has been changed", func() {
log := gbytes.NewBuffer()
logger := lager.NewLogger("test")
logger.RegisterSink(lager.NewWriterSink(log, lager.DEBUG))
logger := slog.New(slog.NewJSONHandler(log, nil))
failureResponse := asFailureResponse(apiresponses.NewFailureResponse(errors.New("my error message"), 600, "log-key"))
failureResponse.ValidatedStatusCode(logger)
failureResponse.ValidatedStatusCode("", logger)
Expect(log).To(gbytes.Say("Invalid failure http response code: 600, expected 4xx or 5xx, returning internal server error: 500."))
})
})
Expand Down
23 changes: 10 additions & 13 deletions failure_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
package brokerapi_test

import (
"github.com/pivotal-cf/brokerapi/v10"
"github.com/pivotal-cf/brokerapi/v10/domain/apiresponses"

"errors"

"log/slog"
"net/http"

"code.cloudfoundry.org/lager/v3"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/pivotal-cf/brokerapi/v10"
"github.com/pivotal-cf/brokerapi/v10/domain/apiresponses"
)

var _ = Describe("FailureResponse", func() {
Expand Down Expand Up @@ -64,7 +62,7 @@ var _ = Describe("FailureResponse", func() {
newError := failureResponse.AppendErrorMessage("and some more details")

Expect(newError.Error()).To(Equal("my error message and some more details"))
Expect(newError.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(newError.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
Expect(newError.LoggerAction()).To(Equal(failureResponse.LoggerAction()))

errorResponse, typeCast := newError.ErrorResponse().(brokerapi.ErrorResponse)
Expand All @@ -80,7 +78,7 @@ var _ = Describe("FailureResponse", func() {
newError := failureResponse.AppendErrorMessage("and some more details")

Expect(newError.Error()).To(Equal("my error message and some more details"))
Expect(newError.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(newError.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
Expect(newError.LoggerAction()).To(Equal(failureResponse.LoggerAction()))
Expect(newError.ErrorResponse()).To(Equal(failureResponse.ErrorResponse()))
})
Expand All @@ -89,26 +87,25 @@ var _ = Describe("FailureResponse", func() {
Describe("ValidatedStatusCode", func() {
It("returns the status code that was passed in", func() {
failureResponse := asFailureResponse(brokerapi.NewFailureResponse(errors.New("my error message"), http.StatusForbidden, "log-key"))
Expect(failureResponse.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(failureResponse.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
})

It("when error key is provided it returns the status code that was passed in", func() {
failureResponse := brokerapi.NewFailureResponseBuilder(errors.New("my error message"), http.StatusForbidden, "log-key").WithErrorKey("error key").Build()
Expect(failureResponse.ValidatedStatusCode(nil)).To(Equal(http.StatusForbidden))
Expect(failureResponse.ValidatedStatusCode("", nil)).To(Equal(http.StatusForbidden))
})

Context("when the status code is invalid", func() {
It("returns 500", func() {
failureResponse := asFailureResponse(brokerapi.NewFailureResponse(errors.New("my error message"), 600, "log-key"))
Expect(failureResponse.ValidatedStatusCode(nil)).To(Equal(http.StatusInternalServerError))
Expect(failureResponse.ValidatedStatusCode("", nil)).To(Equal(http.StatusInternalServerError))
})

It("logs that the status has been changed", func() {
log := gbytes.NewBuffer()
logger := lager.NewLogger("test")
logger.RegisterSink(lager.NewWriterSink(log, lager.DEBUG))
logger := slog.New(slog.NewJSONHandler(log, nil))
failureResponse := asFailureResponse(brokerapi.NewFailureResponse(errors.New("my error message"), 600, "log-key"))
failureResponse.ValidatedStatusCode(logger)
failureResponse.ValidatedStatusCode("", logger)
Expect(log).To(gbytes.Say("Invalid failure http response code: 600, expected 4xx or 5xx, returning internal server error: 500."))
})
})
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/pivotal-cf/brokerapi/v10

go 1.20
go 1.21

require (
code.cloudfoundry.org/lager/v3 v3.0.3
github.com/drewolson/testflight v1.0.0
github.com/go-chi/chi/v5 v5.0.11
github.com/maxbrunsfeld/counterfeiter/v6 v6.8.1
Expand All @@ -21,12 +20,13 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/uuid v1.0.0 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/kr/text v0.2.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 11 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
code.cloudfoundry.org/lager/v3 v3.0.3 h1:/UTmadZfIaKuT/whEinSxK1mzRfNu1uPfvjFfGqiwzM=
code.cloudfoundry.org/lager/v3 v3.0.3/go.mod h1:Zn5q1SrIuuHjEUE7xerMKt3ztunrJQCZETAo7rV0CH8=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
Expand All @@ -9,6 +7,7 @@ github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+Wji
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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=
Expand All @@ -20,7 +19,10 @@ github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
Expand All @@ -32,21 +34,21 @@ github.com/kr/pretty v0.0.0-20160823170715-cfb55aafdaf3 h1:dhwb1Ev84SKKVBfLuhR4b
github.com/kr/pretty v0.0.0-20160823170715-cfb55aafdaf3/go.mod h1:Bvhd+E3laJ0AVkG0c9rmtZcnhV0HQ3+c3YxxqTvc/gA=
github.com/kr/text v0.0.0-20160504234017-7cafcd837844/go.mod h1:sjUstKUATFIcff4qlB53Kml0wQPtJVc/3fWrmuUmcfA=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/maxbrunsfeld/counterfeiter/v6 v6.8.1 h1:NicmruxkeqHjDv03SfSxqmaLuisddudfP3h5wdXFbhM=
github.com/maxbrunsfeld/counterfeiter/v6 v6.8.1/go.mod h1:eyp4DdUJAKkr9tvxR3jWhw2mDK7CWABMG5r9uyaKC7I=
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA=
github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand All @@ -58,16 +60,21 @@ golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
9 changes: 5 additions & 4 deletions handlers/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"

"code.cloudfoundry.org/lager/v3"
"github.com/pivotal-cf/brokerapi/v10/domain"
"github.com/pivotal-cf/brokerapi/v10/internal/logutil"
)

const (
Expand All @@ -29,10 +30,10 @@ var (

type APIHandler struct {
serviceBroker domain.ServiceBroker
logger lager.Logger
logger *slog.Logger
}

func NewApiHandler(broker domain.ServiceBroker, logger lager.Logger) APIHandler {
func NewApiHandler(broker domain.ServiceBroker, logger *slog.Logger) APIHandler {
return APIHandler{broker, logger}
}

Expand All @@ -47,7 +48,7 @@ func (h APIHandler) respond(w http.ResponseWriter, status int, requestIdentity s
encoder.SetEscapeHTML(false)
err := encoder.Encode(response)
if err != nil {
h.logger.Error("encoding response", err, lager.Data{"status": status, "response": response})
h.logger.Error("encoding response", logutil.Error(err), slog.Int("status", status), slog.Any("response", response))
}
}

Expand Down
Loading

0 comments on commit 3437960

Please sign in to comment.