Commit d4d5791
authored
feat!: introduce logger choice via slog (#292)
## Breaking Changes
This package now accepts a `*slog.Logger` from the Go standard library, rather than a [Lager logger](https://github.com/cloudfoundry/lager). This allows the use of alternative loggers.
- This package no longer requires you to import `code.cloudfoundry.org/lager/v3`.
- The constructors `New()`, `NewWithCustomAuth()`, `NewWithOptions()`, and also `AttachRoutes()` all take a `*slog.Logger`
- `apiresponses.FailureResponse` errors with a `ValidatedStatusCode()` method also take a `*slog.Logger` rather than a Lager logger
- The middleware `middlewares.APIVersionMiddleware` has had the `LoggerFactory` field removed, and a new field `Logger` added with type `*slog.Logger`.
If you want to continue to use Lager, you can just convert it to a `*slog.Logger`, for which you will need Lager [v3.0.3](https://github.com/cloudfoundry/lager/releases/tag/v3.0.3) for example:
```go
logger := lager.NewLogger("a-lager-logger")
router := brokerapi.New(serviceBroker, slog.New(lager.NewHandler(logger)), credentials)
```
## Reasons
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.
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`.
Resolves #2671 parent 6992873 commit d4d5791
File tree
28 files changed
+427
-311
lines changed- .github/workflows
- domain/apiresponses
- handlers
- internal/blog
- middlewares
- utils
28 files changed
+427
-311
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 36 | + | |
| 37 | + | |
42 | 38 | | |
43 | | - | |
| 39 | + | |
44 | 40 | | |
45 | 41 | | |
46 | 42 | | |
| |||
91 | 87 | | |
92 | 88 | | |
93 | 89 | | |
94 | | - | |
| 90 | + | |
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
98 | | - | |
| 94 | + | |
99 | 95 | | |
100 | 96 | | |
101 | 97 | | |
| |||
0 commit comments