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

Add OSSignposter sugar and make Logger not fail when testing. #51

Merged
merged 3 commits into from
Apr 23, 2023

Conversation

tgrapperon
Copy link
Owner

The current logger dependency fails when testing. We can't inspect messages that are logged and this dependency is so ubiquitous that it can be cumbersome to have to override it for every tests. It is thus probably preferable to make this dependency work without failing by default when testing. Users who want to assert that no logging occur can override the \.logger dependency with the .unimplemented value.

This commit also exposes some sugar to directly derive an OSSignposter value from a Logger. Its API suffers the same limitations of Logger regarding privacy, so, like Logger, we can't create a configurable/inspectable wrapper of this type. For this reason, the dependency directly produces an OSSignposter value.

You can use the provided subscript to emit signposts on any subsystem/category:

@Dependency(\.logger["Billing"].signpost) var signpost

signpost.emitEvent(
  "Purchase successful",
  "User \(userID, privacy: .private(mask: .hash)) did purchase item \(item, privacy: .auto)"
)

@tgrapperon tgrapperon changed the title Add OSSignposter sugar and make Logger not failing when testing. Add OSSignposter sugar and make Logger not fail when testing. Apr 19, 2023
@tgrapperon tgrapperon merged commit c73a674 into main Apr 23, 2023
@tgrapperon tgrapperon deleted the signpost branch April 23, 2023 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant