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

[TEST]zapslog: fix all with slogtest, support inline group, ignore empty group. #1

Closed
wants to merge 9 commits into from

Conversation

arukiidou
Copy link
Owner

No description provided.

Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
@arukiidou arukiidou closed this Feb 3, 2024
@arukiidou arukiidou reopened this Feb 3, 2024
@arukiidou arukiidou changed the title [TEST]Feature/support slog [TEST]zapslog: fix all with slogtest, support inline group, ignore empty group. Feb 3, 2024
Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Logger name is already tested in WithName.
It doesn't need to be duplicated in every test.
This requires holding onto a slice instead of a single string
to create the nested namespaces.

The slice is cloned on each WithGroup call.
We could probably do this more efficiently with an immutable tree of
references, but deferring that for now.

In the process, also make the addedNamespace business
append during the record.Attrs loop instead of after.
This is more efficient because we don't have to shift the slice over
afterwards.
@arukiidou arukiidou closed this Feb 4, 2024
@arukiidou
Copy link
Owner Author

arukiidou commented Feb 4, 2024

Close as main PR approved.

abhinav added a commit to uber-go/zap that referenced this pull request Feb 5, 2024
…oup. (#1408)

This change adds a test based on testing/slogtest
that verifies compliance with the slog handler contract
(a draft of this was available in #1335),
and fixes all resulting issues.

The two remaining issues were:

- `Group("", attrs)` should inline the new fields
  instead of creating a group with an empty name.
  This was fixed with the use of `zap.Inline`.
- Groups without any attributes should not be created.
  That is, `logger.WithGroup("foo").Info("bar")` should not
  create an empty "foo" namespace (`"foo": {}`).
  This was fixed by keeping track of unapplied groups
  and applying them the first time a field is serialized.

Following this change, slogtest passes as expected.

Refs #1333
Resolves #1334, #1401, #1402
Supersedes #1263, #1335

### TESTS

- passed. arukiidou#1
- This also works in Go 1.22

---------

Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Co-authored-by: Abhinav Gupta <mail@abhinavg.net>
@arukiidou arukiidou deleted the feature/support-slog branch February 5, 2024 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants