os_log 调试和发布版本
os_log Debug & Release Builds
我在 OS_Log 中使用了以下辅助方法,但不确定是否有必要。
我想在我的调试版本中记录内容,但(不一定)在我的发布版本中。
我对编译器是否删除了发布版本中的 os_log 语句感到困惑
public func DLog(_ string: String, subsystem: OSLog, type: OSLogType) {
#if DEBUG
os_log("%{PUBLIC}@", log: subsystem, type: type, string)
#endif
}
我可以直接使用它并删除发布版本的日志吗?
os_log("%{PUBLIC}@", log: subsystem, type: type, string)
我很困惑...
不,Release 中不会删除日志。 OSLogType
只是描述了在 Console.app
中要过滤的消息类型,debug
类型的消息仍将在生产中记录。
在方案中禁用 OS 登录的正确方法是编辑 Release
方案本身:
Set the OS_ACTIVITY_MODE
environment variable to disable
in your
scheme, then you will not see any logs for your app in the console.
虽然这不适用于已存档的应用程序,但无论如何您都不应该真正禁用生产日志记录。如果你真的想要,在这种情况下可以使用预处理器指令。
我在 OS_Log 中使用了以下辅助方法,但不确定是否有必要。
我想在我的调试版本中记录内容,但(不一定)在我的发布版本中。
我对编译器是否删除了发布版本中的 os_log 语句感到困惑
public func DLog(_ string: String, subsystem: OSLog, type: OSLogType) {
#if DEBUG
os_log("%{PUBLIC}@", log: subsystem, type: type, string)
#endif
}
我可以直接使用它并删除发布版本的日志吗?
os_log("%{PUBLIC}@", log: subsystem, type: type, string)
我很困惑...
不,Release 中不会删除日志。 OSLogType
只是描述了在 Console.app
中要过滤的消息类型,debug
类型的消息仍将在生产中记录。
在方案中禁用 OS 登录的正确方法是编辑 Release
方案本身:
Set the
OS_ACTIVITY_MODE
environment variable todisable
in your scheme, then you will not see any logs for your app in the console.
虽然这不适用于已存档的应用程序,但无论如何您都不应该真正禁用生产日志记录。如果你真的想要,在这种情况下可以使用预处理器指令。