TelemetryDeck / SwiftSDK

Swift SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
https://telemetrydeck.com/
Other
148 stars 30 forks source link

Use OSLog when available for structured logging features of Xcode 15 #131

Open Jeehut opened 7 months ago

Jeehut commented 7 months ago

Since Xcode 15 introduced the new structured logging feature in the console I'm using it all the time to hide the log entries of modules I'm currently not interested in or I filter them by log level. This can be easily done by simply right-clicking an entry that was logged using OSLog.

But because TelemetryDeck doesn't make use of the new structured system, I can't hide its entries and they pollute my console during development with INFO messages like these: Bildschirmfoto 2023-11-28 um 12 08 56

Also, there's no need for the prefix [TelemetryDeck: INFO] when using the new OSLog system as it dynamically allows the developer to decide what metadata to show, which typically includes the log level and the library name anyway since they make sense. The new call would simply be something like Logger(subsystem: "TelemetryDeck", category: "Cache").info("your message") (of course the Logger instance could be reused). Also, this way Xcode can highlight warning or error log levels in yellow/red for a richer experience. It also has some more features like output alignment (learn more).

Therefore I suggest adopting OSLog within TelemetryDeck on the platform (versions) that support it and fall back to the current system when OSLog is not available. Like Apple said in the related session in WWDC23, print is only for command line tools and OSLog should be used in applications.