os_log 调试和发布版本

Chr*_*ris 6 logging swift oslog

我将以下辅助方法与 OS_Log 一起使用,但我不确定是否有必要。

我想在我的调试版本中记录内容,但(不一定)在我的发布版本中记录内容。

我对编译器是否删除发布版本中的 os_log 语句感到困惑

public func DLog(_ string: String, subsystem: OSLog, type: OSLogType) {
  #if DEBUG
  os_log("%{PUBLIC}@", log: subsystem, type: type, string)
  #endif
}
Run Code Online (Sandbox Code Playgroud)

我可以直接使用它并在发布版本中删除日志吗?

os_log("%{PUBLIC}@", log: subsystem, type: type, string)
Run Code Online (Sandbox Code Playgroud)

我很困惑...

Pra*_*tti 4

不,日志不会在发布中被删除。它OSLogType只是描述了要过滤的消息类型Console.appdebug类型消息仍将记录在生产中。

\n

在方案中禁用操作系统日志记录的正确方法是编辑Release方案本身:

\n
\n

OS_ACTIVITY_MODE将环境变量设置disable为\n方案中的,然后您将不会在控制台中看到应用程序的任何日志。

\n
\n

虽然这不适用于存档应用程序,但无论如何您都不应该真正禁用生产中的日志记录。如果您确实愿意,在这种情况下可以使用预处理器指令。

\n