-
Notifications
You must be signed in to change notification settings - Fork 301
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
adopt sendable #218
Merged
Merged
adopt sendable #218
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift Logging API open source project | ||
// | ||
// Copyright (c) 2022 Apple Inc. and the Swift Logging API project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of Swift Logging API project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
import Dispatch | ||
@testable import Logging | ||
import XCTest | ||
|
||
class SendableTest: XCTestCase { | ||
#if compiler(>=5.6) | ||
func testSendableLogger() async { | ||
let testLogging = TestLogging() | ||
LoggingSystem.bootstrapInternal(testLogging.make) | ||
|
||
let logger = Logger(label: "test") | ||
let message1 = Logger.Message(stringLiteral: "critical 1") | ||
let message2 = Logger.Message(stringLiteral: "critical 2") | ||
let metadata: Logger.Metadata = ["key": "value"] | ||
|
||
let task = Task.detached { | ||
logger.info("info") | ||
logger.critical(message1) | ||
logger.critical(message2) | ||
logger.warning(.init(stringLiteral: "warning"), metadata: metadata) | ||
} | ||
|
||
await task.value | ||
testLogging.history.assertExist(level: .info, message: "info", metadata: [:]) | ||
testLogging.history.assertExist(level: .critical, message: "critical 1", metadata: [:]) | ||
testLogging.history.assertExist(level: .critical, message: "critical 2", metadata: [:]) | ||
testLogging.history.assertExist(level: .warning, message: "warning", metadata: metadata) | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ services: | |
|
||
shell: | ||
<<: *common | ||
entrypoint: /bin/bash | ||
entrypoint: /bin/bash -l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the value need to be Sendable here? Also this might be breaking as is.
I think to make this non breaking we need:
And then we can go for:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because otherwise
MetadataValue
cannot conform toSendable
, which in term meansLogger.Metadata
cannot conform toSendable
, which in the end meansLogger
can't conform toSendable
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't work either, because this would be a new protocol. Currently, it only requires
CustomStringConvertible
. Maybe atypealias
would work:But I'm not sure if
@preconcurrency
is supported in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I get that. However we could also transform
CustomStringConvertible
to a string directly on the call-site. This would allow us to not requireSendable
. However a class that might change its string representation at a later point, would always be represented by its original value, if it is added to the metadata.@ffried Very good point. Going directly to string might potentially allow us to work around the semver major here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is more to that...
stringConvertible
is currently kind of an escape hatch to pass arbitrary objects to the log handlers. We use it to for example control which file a message is logged to in CocoaLumberjack's log handler. Most of these usages are probably fine with addingSendable
, though.Also, changing the enum case this way will also result in a semver major.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktoso are you saying that adding the Sendable protocol requirement will only yield warnings until Swift 6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, I just confirmed with Doug as well. If you were seeing an error in beta-1 (maybe?), then Doug says this could have been a bug and is still just a warning nowadays and will continue to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case I am also comfortable with this soft break.
@ffried @fabianfett @weissi @Lukasa wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. A warning is fine. 👍
It's the same as when for example a new deprecation is added. There would also be a warning then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with a warning here.