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...
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 todisable
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.