Overly verbose logs produced by 3rd party libraries can be hidden in Swift by setting OS_ACTIVITY_MODE environmnet variable to disable in your run scheme - as shown on the image below.
That silences all NSLog output from your app. I want to disable it only for certain calls. I tried to set the environment variable like this:
setenv("OS_ACTIVITY_MODE", "disable", 1)
And like this
putenv(UnsafeMutablePointer<Int8>(mutating: ("OS_ACTIVITY_MODE=disable" as NSString).utf8String))
The environment is changed as verified by calling print(ProcessInfo.processInfo.environment) but there unlike specifying it in XCode run scheme, the logs are not affected.
Why doesn't it work and how to fix it?

When you set OS_ACTIVITY_MODE to
disable, you disable all log outputs for processes that have access to this environment variable, for example the simulators.When you set the value to either
infoordebugit enables the corresponding logging mode unless it is disabled in the logging preferences for certain log categories.So in order to enable only a certain log category, you have to enable OS_ACTIVITY_MODE, that is, set it either to
infoordebugor leave it at the default, and then disable logging for all other categories.For more information how to do this see the man page for log, type
man login the console.Get the current log preferences for simulators:
In the console type:
xcrun simctl spawn booted log config --statusThat basically means: apply
log config -statusto all booted simulators.This may print the following to your console:
Get the status for a certain category and subsystem
This may print the below to the console:
Get Help
For help, the tools
xcrun simctlandloghave nifty man pages and help pages.For example: type
log config --helpinto the console, it prints:Set the log level for a specific subsystem and category
Get the status again for this sybsystem and category will print: