[swift-evolution] The great renaming and the state of new Unified Logging in Swift

Brandon Knope bknope at me.com
Sat Sep 3 13:13:28 CDT 2016


Thank you! I was looking for this last night and failed. 

Why do you think {public} isn't included?

Sent from my iPad

> On Sep 3, 2016, at 2:06 PM, Ben Rimmington <me at benrimmington.com> wrote:
> 
> 
>> On 3 Sep 2016, at 04:24, Brandon Knope wrote:
>> 
>> I am unsure where to post this…but iOS 10 is introducing a new API for activity tracing and logging.
>> 
>> The API has been “Swift-ified” a little, but it still is a little awkward to use:
>> 
>> os_log("Sender: %{public}@", log: ViewController.ui_log, type: .debug, sender)
>> 
>> (This is taken from: https://developer.apple.com/library/prerelease/content/samplecode/Logging/Introduction/Intro.html#//apple_ref/doc/uid/TP40017510)
>> 
>> Note: the {public} modifier above does not work in swift but does in Objective-C. I have filed a radar for this.
> 
> Activity Tracing (2014) and Unified Logging (2016) APIs are complex preprocessor macros, which are not imported into Swift.
> 
> 	<https://developer.apple.com/videos/play/wwdc2014/714/>
> 
> 	<https://developer.apple.com/videos/play/wwdc2016/721/>
> 
> The os_log_with_type macro in <os/log.h> uses __builtin_os_log_format to encode its arguments into a byte array. The overlay for Swift instead uses its _os_log_encode C++ function, which only recognizes the {private} modifier.
> 
> 	<https://github.com/apple/swift/blob/e06d676d756ce95bd7c32a3029d165c7be5fd4b4/stdlib/public/SDK/os/os.mm#L245-L255>
> 
> 	<https://github.com/apple/swift/tree/master/stdlib/public/SDK/os>
> 
>> A few things:
>> • This looks like how the Dispatch APIs use to look: very C-like which was made to be much better in The Great Renaming
>> • Cannot use Swift’s string interpolation, resulting in the arguments being passed in at the end
>> 
>> For reference, this is what it looks like in Objective-C, showing that SOME renaming has occurred: 
>> os_log_debug(ui_log, "Sender: %{public}@", sender);
>> 
>> This might look more Swift-like:
>> uiLog.log("Sender: %{public}\(sender)”, type: .debug)
>> * Makes “log” a method on an OSLog object 
>> • Uses string interpolation
> 
> The format string of os_log APIs is required to be constant. The overlay uses a StaticString, which isn't ExpressibleByStringInterpolation. SE-0137 also deprecated the protocol, so that it can be redesigned.
> 
> 	<https://github.com/apple/swift-evolution/blob/master/proposals/0137-avoiding-lock-in.md>
> 
> An instance method of OSLog might be better, except when using the `default` object.
> 
> 	OSLog.default.log("message")
> 
> Similarly, the Swift.print(_:separator:terminator:to:) function might be better as a TextOutputStream method.
> 
> -- Ben
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160903/a1fc8208/attachment.html>


More information about the swift-evolution mailing list