Home > Blockchain >  iOS Logger does not print to the Xcode console
iOS Logger does not print to the Xcode console

Time:05-31

I am trying to swap CocoaLumberjack for the iOS native Logger. The only problem is that Logger messages are not logging to the Xcode Console. In the WWDC20 video Explore logging in Swift, Ravi states at 09:02 "If your app is launched from Xcode, you will see them in Xcode's console." However, I'm not seeing the messages. Has anyone else tried this?

Using Xcode 13.4

Here is the code…

import os

extension Logger {

    private static var subsystem = Bundle.main.bundleIdentifier ?? ""

    public static func logDebug(message: String, category: String) {
        logger(category: category)
            .debug("\(message, privacy: .public)")
    }

    public static func logInfo(message: String, category: String) {
        logger(category: category)
            .info("\(message, privacy: .public)")
    }

    public static func logNotice(message: String, category: String) {
        logger(category: category)
            .notice("\(message, privacy: .public)")
    }

    public static func logError(message: String, category: String) {
        logger(category: category)
            .error("\(message, privacy: .public)")
    }

    private static func logger(category: String) -> Logger {
        Logger(subsystem: subsystem, category: category)
    }
}

Here is the call site…

Logger.logNotice(message: "Firebase dispatch event -> \(name) || Parameters -> \(parameters.debugDescription)",
                 category: String(describing: FirebaseSDKDispatch.self))

CodePudding user response:

It does work if I create a new app from scratch. I will need to investigate my commercial app further.

import os
import UIKit

class ViewController: UIViewController {

    let log = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "app")
    override func viewDidLoad() {
        super.viewDidLoad()
        log.debug("You better print in the Xcode console!")
    }
}
  • Related