Automatically use different log levels per xcode configuration.
Starting with Xcode 4, the DEBUG
preprocessor macro is automatically set when building for debug (as opposed to release). So you can use this to automatically get different log levels depending upon your current build configuration.
#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_WARN;
#endif
Nothing else is needed. (No changes required of your xcode project.) If the DEBUG macro isn't set in your project, it likely means you originally created the project with Xcode 3 (or before the DEBUG macro became standard). In that case, read on.
Xcode has powerful configuration tools that we can tap into to automatically use different log levels depending on whether we're compiling in Debug vs Release mode.
When we're done we'll be able to have code like this:
#ifdef CONFIGURATION_DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_WARN;
#endif
Open your Xcode project and go to:
Project -> Edit Project Settings
Now change the configuration to Debug Configuration.
Filter on "preprocessor" so you can find the Preprocessor Macros Not Used In Precompilation setting.
Now add a CONFIGURATION_DEBUG value to this setting.
Your project settings should look like this:
Next, switch the configuration to Release Configuration.
Now add a CONFIGURATION_RELEASE to the Preprocessor Macros Not Used In Precompilation setting.
Your project settings should look like this:
And that's all there is to it. You're done!\
And this isn't limited to just logging.
You can use the #ifdef CONFIGURATION_DEBUG
anywhere you want in your project if you feel the need to differentiate something between your debug and release builds.