swiftxcodeswift-playgroundoslog

OSLog Logger doesn't work on XCode Playground: Couldn't lookup symbols: ___dso_handle


I want to test new iOS 14 Logger in Playground but I found next issue:

// MyLog.playground

import os

let logger = Logger()
logger.log("Hello OSLog")

Outputs:

error: Couldn't lookup symbols:
  ___dso_handle
  ___dso_handle

The same I have with old OSLog API:

os_log("Hello OSLog")

Is it possible to use OSLog with playgrounds?


Solution

  • There is a workaround to work with Logger on Playgrounds. You should make new file inside your playground (e.g. Sources/Log.swift) and implement code there:

    // Log.swift
    
    import os
    
    let logger = Logger()
    
    public func log(_ text: String) {
        logger.log("\(text)")
    }
    
    // MyLog.playground
    
    log("Hello OSLog")