Broken OS.Log function os_log

Sorry for posting this here but the other discussion groups / categories App Frameworks / System Frameworks / "BETA" don't have a suitable category to talk about this issue which seems only related using unified logging under swift. After upgrading to the most recent Xcode 9 beta 3.



Function

func os_log(StaticString, dso: UnsafeRawPointer, log: OSLog, type: OSLogType, CVarArg...)


Issue


error: Couldn't lookup symbols:

___dso_handle

Replies

The signature is


func os_log(_ message: StaticString, dso: UnsafeRawPointer? = #dsohandle, log: OSLog = default, type: OSLogType = default, _ args: CVarArg...)

Palm on face, spend a few minutes and compare both functions Claude31.


Additional info

The os_log function fails to compile under Xcode 9 B3 playgrounds but works within a typical project

___


Playgrounds



Typical Project - no precompile runtime issues

did you


import os

Don't allow the ego to get the best of you bud, I have been at this longer than you can think!

If you click the hyper link attached to the function noted in the intial post it takes you to the offical apple docs for the function which is no different than the code you copied and pasted out of Xcode. A little research on your behalf goes a long way before trying to gain a few forum points.


Plug this code snippet into Xcode 9 B3 playgrounds


import UIKit
import PlaygroundSupport
import os.log
class MyViewController : UIViewController {

    static let ui_log = OSLog(subsystem: "unified-logger-line", category: "UI")

    override func loadView() {
        super.loadView()
    
        let view = UIView()
        view.backgroundColor = .white
        let label = UILabel()
        label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
        label.text = "Hello World!"
        label.textColor = .black
        os_log("Paper is useless in our modern world!", log: MyViewController.ui_log, type: .info)
        view.addSubview(label)
        self.view = view
    
    
    }
}
/
PlaygroundPage.current.liveView = MyViewController()

Playgrounds Output

Playground execution failed:
error: Couldn't lookup symbols:
  ___dso_handle

In the meantime to grabbing a few more forum points🙂, I experimented a little in XCode 8.3 playground. But probably you have already investigated.


if replaced the os_log call with :

        os_log("Paper is useless in our modern world!", dso: nil, log: MyViewController.ui_log, type: .info)


then the symbol not found error disappeared (becasue default value #dsohandle is no more assigned), but playground crashes on

     PlaygroundPage.current.liveView = MyViewController()


Tested with:

        var dso: UnsafeRawPointer? = #dsohandle
        os_log("Paper is useless in our modern world!", dso: dso, log: MyViewController.ui_log, type: .info)

same symbol not found error, because of the first line (commenting out the second line does not eliminate the error)

Playground execution failed: error: Couldn't lookup symbols:

___dso_handle

Just to check, I tried with :

        os_log("Paper is useless in our modern world!", dso: __DSO_HANDLE__, log: MyViewController.ui_log, type: .info)

Error message is

__DSO_HANDLE__ has been replaced with #dsohandle in Swift 3

which shows the symbol is known.

A minimal conclusion: problem is not new in XCode9, did exist in 8.3