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 inConsole.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: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.