os.log 有什么用?
What is os.log for?
我正在阅读一些 Swift 教程,了解如何构建简单的应用程序,因为我刚刚开始编写代码。我想让我的应用程序 iOS 9 兼容,因为我有一个 iPad 3。但是,所有 os.log
语句都会在 Xcode 中生成一个错误,告诉我添加一个if #avaliable
语句在任何 os.log
语句之前。 os.log 有什么作用,如果我需要它,使用 if #avaliable
语句实现 iOS 9 兼容性是否有问题?如果不是,iOS 9 在 if #avaliable
语句之后的 else
语句中的等效代码是什么?谢谢。
Unified logging is available in iOS 10.0 and later, macOS 10.12 and
later, tvOS 10.0 and later, and watchOS 3.0 and later, and supersedes
ASL (Apple System Logger) and the Syslog APIs. Historically, log
messages were written to specific locations on disk, such as
/etc/system.log. The unified logging system stores messages in memory
and in a data store, rather than writing to text-based log files.
没有 iOS9 等价物。您可以使用非常流行的第三方日志记录工具,例如 CocoaLumberjack。
作为如何使用此日志记录的具体示例:
if #available(iOS 10.0, *) {
let bundleID:String = Bundle.main.bundleIdentifier ?? "unknown"
let oslog = OSLog(subsystem: bundleID, category: "Model")
os_log("%@", log: oslog, type: .info, message)
}
我正在阅读一些 Swift 教程,了解如何构建简单的应用程序,因为我刚刚开始编写代码。我想让我的应用程序 iOS 9 兼容,因为我有一个 iPad 3。但是,所有 os.log
语句都会在 Xcode 中生成一个错误,告诉我添加一个if #avaliable
语句在任何 os.log
语句之前。 os.log 有什么作用,如果我需要它,使用 if #avaliable
语句实现 iOS 9 兼容性是否有问题?如果不是,iOS 9 在 if #avaliable
语句之后的 else
语句中的等效代码是什么?谢谢。
Unified logging is available in iOS 10.0 and later, macOS 10.12 and later, tvOS 10.0 and later, and watchOS 3.0 and later, and supersedes ASL (Apple System Logger) and the Syslog APIs. Historically, log messages were written to specific locations on disk, such as /etc/system.log. The unified logging system stores messages in memory and in a data store, rather than writing to text-based log files.
没有 iOS9 等价物。您可以使用非常流行的第三方日志记录工具,例如 CocoaLumberjack。
作为如何使用此日志记录的具体示例:
if #available(iOS 10.0, *) {
let bundleID:String = Bundle.main.bundleIdentifier ?? "unknown"
let oslog = OSLog(subsystem: bundleID, category: "Model")
os_log("%@", log: oslog, type: .info, message)
}