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

Enforce Sendable conformance for LogHandlers Swift-Log, and make Logger Sendable #217

Closed
wants to merge 1 commit into from

Conversation

Joannis
Copy link

@Joannis Joannis commented Feb 4, 2022

Enforce Sendable conformance for LogHandlers Swift-Log, and make Logger Sendable. See #216

Motivation:

Swift-Log is adopted in many libraries, and as the language has recently involved in exciting new directions, these new features have been the subject of improvement and innovation. Many libraries aim at implementing Sendable, which means that many types that carry swift-log's Logger will quickly see warnings pop up all over these projects.

As swift-log is a loved and essential part of the swift ecosystem, it too should adopt the new Swift standards.

Modifications:

  • Require LogHandler implementations to conform to Sendable
  • Conform Logger to Sendable
  • Updated tests to support the new Sendable requirements

Result:

Swift-Log supports Sendable. Requires iOS 13+, macOS 10.15+ and Swift 5.5+.
This'll obviously require a semver major.

@swift-server-bot
Copy link

Can one of the admins verify this patch?

10 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Joannis
Copy link
Author

Joannis commented Feb 4, 2022

That bot is very eager for a review!

@ktoso
Copy link
Member

ktoso commented Feb 9, 2022

@swift-server-bot test this please

platforms: [
.iOS(.v13),
.macOS(.v10_15),
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't just do that like this; we need to support old platforms too

@@ -113,7 +113,7 @@
/// Please note that the above `LogHandler` will still pass the 'log level is a value' test above it iff the global log
/// level has not been overridden. And most importantly it passes the requirement listed above: A change to the log
/// level on one `Logger` should not affect the log level of another `Logger` variable.
public protocol LogHandler {
public protocol LogHandler: Sendable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't just do it like this, we'd need to follow the trickery with the sendable availability as explained in https://github.com/swift-server/guides/blob/main/docs/concurrency-adoption-guidelines.md#backwards-compatibility-of-declarations-and-checked-swift-concurrency

So we'd need _SwiftLog_Sendable and the entire dance

@@ -1074,6 +1074,8 @@ let systemStdout = WASILibc.stdout!
/// `StreamLogHandler` is a simple implementation of `LogHandler` for directing
/// `Logger` output to either `stderr` or `stdout` via the factory methods.
public struct StreamLogHandler: LogHandler {
public typealias Stream = TextOutputStream & Sendable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has to use the compatibility trickery

Copy link
Member

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite right, we need to treat this very carefully so older clients can still adopt even if they are on old swift IMHO

@ktoso
Copy link
Member

ktoso commented Jul 26, 2022

Sendable conformance has been done in #218 in a more compatible way.

Thank you for the PR though!

@ktoso ktoso closed this Jul 26, 2022
@easydev991
Copy link

Sendable conformance has been done in #218 in a more compatible way.

Thank you for the PR though!

Hello! I still get warning about Logger not being Sendable inside a Sendable-class. Is it a new feature in Xcode 15.3, or is it a bug?

@Lukasa
Copy link
Contributor

Lukasa commented Mar 12, 2024

Can you show your code? Are you storing it as var?

@easydev991
Copy link

Can you show your code? Are you storing it as var?

Cannot show the code now.
I store it as a let inside a @MainActor-class

@Lukasa
Copy link
Contributor

Lukasa commented Mar 12, 2024

What version of swift-log have you resolved?

@easydev991
Copy link

What version of swift-log have you resolved?

I do not use swift-log, I import OSLog and then use Logger inside a class like this:

import OSLog

@MainActor
protocol SomeProtocol {}

final class MyClass: SomeProtocol {
  private let logger = Logger(subsystem: "Subsystem", category: "MyClass")
}

An interesting moment: in one file it helped me to make @preconcurrency import OSLog, but in other file it does not work. I have strict concurrency check (complete) in my app build settings.

@Lukasa
Copy link
Contributor

Lukasa commented Mar 12, 2024

This repository is not for os log, it's for swift-log. Issues with os log should be taken to Apple's developer forums.

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

Successfully merging this pull request may close these issues.

5 participants