我正在尝试将CocoaLumberjack换成iOS本地Logger。唯一的问题是Logger消息没有记录到Xcode控制台。在WWDC20视频探索Swift登录中,Ravi在09:02说:"如果你的应用程序是从Xcode启动的,你会在Xcode的控制台上看到它们。"但是,我没有看到这些信息。有人试过吗?
使用Xcode 13.4
代码如下:
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)
}
}
这是呼叫地点…
Logger.logNotice(message: "Firebase dispatch event -> (name) || Parameters -> (parameters.debugDescription)",
category: String(describing: FirebaseSDKDispatch.self))
如果我从头开始创建一个新的应用程序,它确实工作。我需要进一步调查我的商业应用程序。
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!")
}
}