State of the Logging (swift-log) package

I’m trying to determine the state of the Logging packages on Swift in general, and in particular on Apple platforms.

On Linux/non-Apple Platforms

As far as I understand, on non-Apple platform, the default logging package would be Apple’s swift-log. It has customisable loggers and works well.

On Apple Platforms

This is where things get weird.

My latest (but dated) news on the subject was that on these platforms, logging should be done using Apple’s unified logging, namely os_log.
In theory there is nothing stopping us from using swift-log in an Apple project with an os_log logger. However, the swift-log repo tells us we should not do that otherwise we lose performance, and we cannot use the special private/public modifiers on the string formatting (GitHub - apple/swift-log: A Logging API for Swift).
Question 1: Is this still true?

All of this was a while ago.
Apparently now on latest SDKs for Apple platforms there is a Logger struct readily available. I guess (and doc says so) we should use this.
Apparently Apple’s Logger supports privacy level in string interpolation, which makes it somewhat incompatible with swift-log.
Question 2: Are there any other differences between the Logger from Apple and the one in swift-log?

On Both

Question 3: How are we supposed to log properly on cross-platform projects?
Because of the privacy-level stuff from Apple’s Logger, I guess we cannot cheat in any way to have a Logger working with both systems. We have to commit to one logger, and because swift-log works everywhere we should use that one and forget about privacy-levels, at least while they have not been implemented in swift-log.



os_log has been replaced by Logging on Apple platforms, but yes, it is still true that you should not encapsulate the system logger on Apple platforms.

Yes. The Apple Platform Logger cannot be redirected to other logging backends: it only logs through the default system logging path. It also does not have a structured metadata field.

As you note, because you can’t encapsulate the system logger, it’s very hard to log to both. In principle you could encapsulate swift-log in an API that matches the OS logging feature, but this would require to to emulate the string interpolation feature, and would need to be held very carefully to not have poor logging performance on non-Apple platforms.

1 Like
Terms of Service

Privacy Policy

Cookie Policy