How do I use swiftlog in conjunction with os.log?
Closed this issue · 2 comments
not sure what is the best practice here. Should I be using os.log or should I be using swift-log?
The best practice is to use os.log directly because going through the swift-log adapters prevents some optimizations and smarts os log is able to perform.
The bridges exist for libraries which don't know if they'll be used on the server or OS, and thus can use swift-log, and if an end user wants to make those log into oslog they can configure an appropriate adapter backend.
As an application developer however, developing an iOS/macOS app, you most definitely should be using OSLog directly.
Hope this helps! Maybe it's time we add such wording to the readme, I'll work on something for this :)
Actually, we have this wording already but perhaps it's not as prominent as it should be:
Important Note: we recommend using os_log directly as decribed here. Using os_log through swift-log using this backend will be less efficient and will also prevent specifying the privacy of the message. The backend always uses %{public}@ as the format string and eagerly converts all string interpolations to strings. This has two drawbacks: 1. the static components of the string interpolation would be eagerly copied by the unified logging system, which will result in loss of performance. 2. It makes all messages public, which changes the default privacy policy of os_log, and doesn't allow specifying fine-grained privacy of sections of the message. In a separate on-going work, Swift APIs for os_log are being improved and made to align closely with swift-log APIs. References: Unifying Logging Levels, Making os_log accept string interpolations using compile-time interpretation.