os_log Debug & Release Builds

1.3k views Asked by At

I'm using the following helper method with OS_Log, but I'm not sure if it's necessary.

I want to log things in my Debug builds, but not(necessarily) in my Release builds.

I'm confused as to whether the compiler removes os_log statements in Release builds

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

Could I just use it directly and logs are stripped for Release builds?

os_log("%{PUBLIC}@", log: subsystem, type: type, string)

I'm confused...

1

There are 1 answers

0
Pranav Kasetti On BEST ANSWER

No, the logs won't be stripped in Release. The OSLogType just describes the type of message to filter in Console.app, debug type messages will still be logged in production.

The correct way to disable OS logging in a scheme is to edit the Release scheme itself:

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.

This won't work for Archived apps though, but you should never really disable logging in production anyway. If you really want to, it’s possible to use preprocessor directives in this case.