Disable iOS OSLog on release build

1.5k views Asked by At

I want to disable OSLog for my iOS app (release build). I am not using OSLog in my app but I still see some logs in the console app logged by the apple frameworks (like libnetwork, Corefoundation, SystemConfiguration etc.,). Is there is a way to completely turn off all the logs for the app?

I added the below values to the environment variable but still, it disables the logs only when I ran the application from XCode however, I still see OSLog for my app on the console app when I launch it by clicking the App Icon.

OS_ACTIVITY_MODE=disable

Note: My app uses both Objective C and Swift programming language and disabled NSLog(Objective C) and print(Swift) and I do not have an issue with it. I want to disable all the logs including logs from the Apple framework for my release build.

2

There are 2 answers

0
Ol Sen On

just a quick solution but not the most comfortable..

#ifndef DEBUG
#define OSLog(FORMAT, ...) {}
#endif

if DEBUG mode is not used, which should be RELEASE then, OSLog() will be exchanged with void function content at compile time. Which will apply to code you wrote, not turning off Logs in general outside your sources scope.

0
MGY On

To Disable OSLog on Release Builds

You could create a global function like:

func customLogger(_ category: String) -> OSLog {
#if DEBUG
    return OSLog(subsystem: Bundle.main.bundleIdentifier!, category: category)
#else
    return OSLog.disabled
#endif
}

For more detailed and advanced scenarios please check Apple's official documentation.