-
Notifications
You must be signed in to change notification settings - Fork 306
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
Use StaticString for Parameter file and function #136
Comments
I believe @weissi explored this topic in great depth with specific focus on OSLog so he should be able to answer best here. |
I think
@ShivaHuang I would suggest that everybody switch to |
Great point! I misunderstood the performance and memory usage between The logging backend use However, after digging into their code, they also convert the BTW, while searching some similar use case in Apple's SDK, I found some functions use
Will Apple also change their code? 🤣 |
@ShivaHuang until Swift 4.2, StaticString was much faster which is why XCTAssertEqual was designed the way it is. Same for assertionFailure etc, now they can’t easily change that because of source/ABI compat. Also: StaticString should just be 1 word, there’s no reason except that nobody noticed until the ABI was fixed 😬 |
Abstract
The proposal from SSWG: Server Logging API suggest using
String
for parameters like#file
and#function
.But is using
StaticString
a better design in practice?Current Situation
Log functions take
String
for#file
and#function
. But some logging frameworks (backends) takeStaticString
for these parameters.Problem
The main problem is
String
can not convert toStaticString
, so for those frameworks takeStaticString
as parameters, there is no way to build aLogHandler
for them.The only workaround I found is discard these information. For those backends don't care about the
#file
or#function
this will be fine, like swift-log-oslog.However, the others will always get the
#file
and#function
inLogHandler
, not the actual place in the program. This will be a big problem.Proposed Solution
If we changed the parameter type from
String
toStaticString
, those backends requireStaticString
can take it without problems. And those requireString
can easily convert it to what they want. A simple extension can do the trick.The cons of this change is, it breaks the API compatibility, log handler providers need to update their code for this chage.
Any suggestions about this idea?
The text was updated successfully, but these errors were encountered: