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

SwiftLog + OSLog StringInterpolation #208

Closed
shaps80 opened this issue Sep 20, 2021 · 3 comments
Closed

SwiftLog + OSLog StringInterpolation #208

shaps80 opened this issue Sep 20, 2021 · 3 comments

Comments

@shaps80
Copy link

shaps80 commented Sep 20, 2021

I just wanted to share a library I've made that adds string interpolation to the SwiftLog implementation.

Unfortunately I couldn't see a way to do this without copy/pasting the code (would love any ideas on improving this) but I have kept the code almost entirely untouched and the copyright notices in tact of course.

I am not submitting a PR as I'm fairly certain this is pretty Apple platforms specific and wouldn't make sense in other environments.

But in case its useful to anyone else, here it is: https://github.com/shaps80/Logging

I've started adding tests as well and the implementation is not yet complete, but any feedback/issues/contributions are certainly welcome.

shaps_2021-Sep-20

@shaps80
Copy link
Author

shaps80 commented Sep 22, 2021

@ShivaHuang / @ktoso / @weissi / @tomerd – If any of you are able to take a look, I'd love to know if this is something that might make sense in the actual library itself. I'm guessing not if it's not already been done. There are likely other platform specific issues I'm unaware of. But I thought I'd ask the question in case this is something that might be worthy of a more complete PR?

Also, I'm only referring to the string interpolation implementation, not the formatter I've included in my repo as that's obviously not relevant here.

Thanks.

@weissi
Copy link
Member

weissi commented Sep 22, 2021

@shaps80 this cannot be added to SwiftLog without changing API. Also, SwiftLog encourages you to add variable data in the metadata section. For example:

logger.debug("Found results", metadata["count": "\(results.count)"])

If you need log privacy, then I would encourage this strategy in your logging backend:

  • by default print only the message and the metadata keys, hide all metadata values (because they may contain private data)
  • for certain fields that you know have no private info, show them. Basically have an allow list of keys you know are fine to print, redact all other metadata values
  • make sure that only static data is provided in the actual log message

OSLog's API assumes that every piece of software can always tell whether something is private or not. But that's difficult to tell. For example in most cases a URL for a HTTP library is not private data. But in certain cases it may be. That's why I'd encourage you to use the above way.

The reason that SwiftLog encourages to put all variable data in the metadata has a couple of reasons:

  • privacy controls (as described above)
  • filtering in log aggregation systems, you can just filter by the log message

@shaps80
Copy link
Author

shaps80 commented Sep 22, 2021

Interesting, I guess the ergonomics for an API using that approach are less than ideal though. Hence why I thought the OSLog approach was more appropriate, particularly for apps.

Still, thank you for clarifying this really helped and I'll do some more thinking on your feedback above. Really appreciate you taking the time to respond 👍

@shaps80 shaps80 closed this as completed Sep 22, 2021
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

No branches or pull requests

2 participants