Skip to content
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
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,17 +594,35 @@ ctrl, _ := NewAppController(
)
```

The controller stores contextual information (channel, correlation ID,
direction, …) in the `context.Context` passed to your logger. To retrieve it
without unwrapping each key manually, use `extensions.LogInfosFromContext`:
The generated code passes the contextual information (channel, correlation ID,
direction, provider, broker message, version) directly to your logger as
explicit `LogInfo` arguments at every log call. Your logger therefore only has
to log the `msg` and the `info` it is given — there is no need to unwrap any
context key:

```golang
func (logger SimpleLogger) Info(ctx context.Context, msg string, info ...extensions.LogInfo) {
info = append(info, extensions.LogInfosFromContext(ctx)...)
// 'info' already contains the contextual values (channel, correlationID, …)
// ... log msg with info
}
```

> **Migration note (from versions where loggers enriched from context):** the
> contextual values are no longer read from the `context.Context` by the
> built-in `Text`/`ECS` loggers — they are now supplied as explicit `LogInfo`
> arguments by the generated code, using the generic keys returned by
> `extensions.LogInfosFromContext` (`channel`, `correlationID`, `brokerMessage`,
> `direction`, `provider`, `version`). This means:
> * The built-in `Text` and `ECS` loggers now emit those generic keys instead of
> their previous custom names (e.g. ECS no longer maps to `trace.id`,
> `event.action`, `event.original`).
> * Custom loggers receive everything as arguments and no longer need to call
> `extensions.LogInfosFromContext` themselves.
>
> The values are still stored in the `context.Context` (it stays useful for
> other purposes), so a custom logger that *wants* to keep reading from context
> can still call `extensions.LogInfosFromContext(ctx)`.

### Versioning

If you are in need to do a migration or support multiple versions of your
Expand Down
12 changes: 6 additions & 6 deletions examples/helloworld/v2/nats/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions examples/helloworld/v3/nats/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions examples/ping/v2/kafka/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions examples/ping/v2/kafka/user/user.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions examples/ping/v2/nats-jetstream/app/app.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading