-
-
Notifications
You must be signed in to change notification settings - Fork 64
Adopt swift-log #290
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 swift-log #290
Conversation
stackotter
left a comment
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.
Thanks for these changes, and all of the accompanying documentation! I've requested a few formatting/wording changes.
Loading Swift Bundler metadata is something that I can see going wrong and being important to be able to debug. I had a quick think about the possibility of introducing a new static method to the App protocol (with an empty default implementation) to house logger customisation. But I think it's likely that some logger implementations would need information from the app's metadata (such as a Sentry client token). I think that the best solution would be to store the metadata loading errors somewhere and then dump them to the logger as soon as it gets created. Would you be happy to implement that?
|
Okay, so. Whenever Swift 7 decides to come around, #if compiler(>=6.0)
// deliberately use `public import` here to allow the user access to
// `LoggingSystem`
public import Logging
#else
// before 6.0, this behaves like `public import`
import Logging
#endifHowever, right now that results in a warning, because we don't use any of Logging's APIs in public declarations. As far as I can tell, there isn't any way to get rid of this warning without either:
So here's what I'm thinking. Instead of asking the user to set the backend in var logHandler: LogHandler { get }(Logging calls backends "log handlers"). This requirement will have a default implementation that simply uses the built-in With this mechanism, not only do we solve the problem of not using Logging in public API by adding this requirement, but we also give ourselves the freedom to use whatever backend we want by default. (With the current implementation, we can't use anything other than the default |
|
I noticed that |
stackotter
left a comment
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.
Looks really good now. I've just requested some documentation wording changes, but the code looks great.
stackotter
left a comment
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.
Just a couple more requests (your throwing changes came through while I was doing my previous review)
Are you intending for this to reexport the Logging API so that user's don't have to import it themselves? That's different to |
stackotter
left a comment
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.
Sorry, just one more small change due to a logging statement that I accidentally left in #278, but other than that this is ready to merge.
No, |
|
If my understanding is correct, |
I think that's true, but I'd personally like to spare people the hassle of doing that and having to match their version of |
|
Looks like the swift-log version might have to be 1.6.0 not 1.7.0 (the 5.10-based CIs have failed again) |
|
Okay, so for whatever reason the CI seems to still be trying to use 1.8.0 even though I very explicitly set the swift-log version to 1.6.4... |
|
It seems Package.resolved wasn't updated properly, that might be it. |
This at least partially solves #267 by adopting swift-log. The logger is initialized immediately after calling
App.init(), such that users can useLoggingSystem.bootstrap(_:)in their app's initializer to redirect messages wherever they want. (This does mean that the logger is unavailable inextractSwiftBundlerMetadata(), since that's called beforeApp.init().)This PR also adds a small documentation article detailing how to customize the logger, and mentioning the caveat that doing so outside of the app's initializer will not work.