Is OSLog Logger Sendable?

The new Xcode 15.3 Release Candidate produces errors with strict concurrency checking that the usual pattern of using OSLog with a static property like static let logger = Logger(...) is not safe.

"Static property 'logger' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6"

Is Logger thread safe and just not marked Sendable? Would it be "safe" to use nonisolated(unsafe) static let logger = Logger(...)?

Answered by DTS Engineer in 781922022

Logger should be sendable. Under the covers, it’s an immutable struct with a single OSLog property, and that in turn is just a wrapper around the C os_log_t which is definitely thread safe.

We already have a bug on file requesting that it be marked sendable (r. 122467426). Sadly, the fix didn’t make Xcode 15.3.

In the meantime, I think it’s fine for you to suppress the warning with that annotation. I also recommend that you add this:

#if swift(>=6.0)
    #warning("Reevaluate whether this decoration is necessary.")
#endif

to remind you to revisit this when Swift 6 lands.

IMPORTANT I’m not promising that this’ll be fixed in Swift 6 [1], just that it makes sense to reevaluate it then.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Because that’s a statement about The Future™, and I can’t predict that.

Accepted Answer

Logger should be sendable. Under the covers, it’s an immutable struct with a single OSLog property, and that in turn is just a wrapper around the C os_log_t which is definitely thread safe.

We already have a bug on file requesting that it be marked sendable (r. 122467426). Sadly, the fix didn’t make Xcode 15.3.

In the meantime, I think it’s fine for you to suppress the warning with that annotation. I also recommend that you add this:

#if swift(>=6.0)
    #warning("Reevaluate whether this decoration is necessary.")
#endif

to remind you to revisit this when Swift 6 lands.

IMPORTANT I’m not promising that this’ll be fixed in Swift 6 [1], just that it makes sense to reevaluate it then.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Because that’s a statement about The Future™, and I can’t predict that.

Thank you, good to know 👍

os.log types seem to be annotated as Sendable starting with Xcode 16 β3.

Is OSLog Logger Sendable?
 
 
Q