Replaced preprocessor constant "NDEBUG" by the more standard "DEBUG" one and flipped behavior accordingly

This commit is contained in:
Pierre-Olivier Latour
2014-10-10 10:27:07 -07:00
parent 143e38c968
commit 420ddc3eac
7 changed files with 22 additions and 22 deletions
-1
View File
@@ -28,7 +28,6 @@ Pod::Spec.new do |s|
cs.ios.frameworks = 'MobileCoreServices', 'CFNetwork'
cs.osx.library = 'z'
cs.osx.framework = 'SystemConfiguration'
cs.compiler_flags = '-DNDEBUG' # TODO: Only set this for Release configuration
end
s.subspec 'WebDAV' do |cs|
+1 -1
View File
@@ -512,6 +512,7 @@
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
ONLY_ACTIVE_ARCH = YES;
@@ -539,7 +540,6 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PREPROCESSOR_DEFINITIONS = NDEBUG;
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
+5 -4
View File
@@ -33,8 +33,8 @@
/**
* Log levels used by GCDWebServer.
*
* @warning kGCDWebServerLogLevel_Debug is only available if "NDEBUG" is not
* defined when building.
* @warning kGCDWebServerLogLevel_Debug is only functional if the preprocessor
* constant "DEBUG" is is non-zero at build time.
*/
typedef NS_ENUM(int, GCDWebServerLogLevel) {
kGCDWebServerLogLevel_Debug = 0,
@@ -489,8 +489,9 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
/**
* Sets the current log level below which logged messages are discarded.
*
* The default level is either DEBUG or INFO if "NDEBUG" is defined at build-time.
* It can also be set at runtime with the "logLevel" environment variable.
* The default level is INFO (or DEBUG if the preprocessor constant "DEBUG"
* is non-zero at build time).
* It can also be set at run time with the "logLevel" environment variable.
*/
+ (void)setLogLevel:(GCDWebServerLogLevel)level;
+4 -4
View File
@@ -62,10 +62,10 @@ NSString* const GCDWebServerAuthenticationMethod_Basic = @"Basic";
NSString* const GCDWebServerAuthenticationMethod_DigestAccess = @"DigestAccess";
#ifndef __GCDWEBSERVER_LOGGING_HEADER__
#ifdef NDEBUG
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info;
#else
#if DEBUG
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Debug;
#else
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info;
#endif
#endif
@@ -1138,7 +1138,7 @@ static void _LogResult(NSString* format, ...) {
_LogResult(@" Bodies not matching:\n Expected: %lu bytes\n Actual: %lu bytes", (unsigned long)expectedBody.length, (unsigned long)actualBody.length);
success = NO;
#if !TARGET_OS_IPHONE
#ifndef NDEBUG
#if DEBUG
if (GCDWebServerIsTextContentType([expectedHeaders objectForKey:@"Content-Type"])) {
NSString* expectedPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
NSString* actualPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
+7 -7
View File
@@ -84,13 +84,7 @@ extern void GCDLogMessage(GCDWebServerLogLevel level, NSString* format, ...) NS_
#define LOG_ERROR(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Error) GCDLogMessage(kGCDWebServerLogLevel_Error, __VA_ARGS__); } while (0)
#define LOG_EXCEPTION(__EXCEPTION__) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Exception) GCDLogMessage(kGCDWebServerLogLevel_Exception, @"%@", __EXCEPTION__); } while (0)
#ifdef NDEBUG
#define DCHECK(__CONDITION__)
#define DNOT_REACHED()
#define LOG_DEBUG(...)
#else
#if DEBUG
#define DCHECK(__CONDITION__) \
do { \
@@ -101,6 +95,12 @@ extern void GCDLogMessage(GCDWebServerLogLevel level, NSString* format, ...) NS_
#define DNOT_REACHED() abort()
#define LOG_DEBUG(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Debug) GCDLogMessage(kGCDWebServerLogLevel_Debug, __VA_ARGS__); } while (0)
#else
#define DCHECK(__CONDITION__)
#define DNOT_REACHED()
#define LOG_DEBUG(...)
#endif
#endif
+1 -1
View File
@@ -359,7 +359,7 @@ int main(int argc, const char* argv[]) {
if (webServer) {
Delegate* delegate = [[Delegate alloc] init];
if (testDirectory) {
#ifndef NDEBUG
#if DEBUG
webServer.delegate = delegate;
#endif
fprintf(stdout, "<RUNNING TESTS FROM \"%s\">\n\n", [testDirectory UTF8String]);
+4 -4
View File
@@ -303,20 +303,20 @@ HTTP connections are often initiated in batches (or bursts), for instance when l
Debug Builds & Custom Logging
=============================
When building GCDWebServer in "Debug" mode versus "Release" mode, GCDWebServer logs a lot more information and also performs a number of internal consistency checks. To disable this behavior, make sure to define the preprocessor constant ```NDEBUG``` when compiling GCDWebServer. In Xcode target settings, this can be done by adding ```NDEBUG``` to the build setting ```GCC_PREPROCESSOR_DEFINITIONS``` when building in Release configuration (this is done automatically for you if you use CocoaPods).
When building GCDWebServer in "Debug" mode versus "Release" mode, GCDWebServer logs a lot more information and also performs a number of internal consistency checks. To enable this behavior, define the preprocessor constant ```DEBUG=1``` when compiling GCDWebServer. In Xcode target settings, this can be done by adding ```DEBUG=1``` to the build setting ```GCC_PREPROCESSOR_DEFINITIONS``` when building in Debug configuration.
It's also possible to replace the logging system used by GCDWebServer by a custom one. Simply define the preprocessor constant ```__GCDWEBSERVER_LOGGING_HEADER__``` to the name of a header file (e.g. "MyLogging.h") that defines these macros:
```
#define LOG_DEBUG(...) // Should not do anything if NDEBUG is defined
#define LOG_DEBUG(...) // Should not do anything unless the preprocessor constant DEBUG is non-zero
#define LOG_VERBOSE(...)
#define LOG_INFO(...)
#define LOG_WARNING(...)
#define LOG_ERROR(...)
#define LOG_EXCEPTION(__EXCEPTION__)
#define DCHECK(__CONDITION__) // Should not do anything if NDEBUG is defined or abort if __CONDITION__ is false
#define DNOT_REACHED() // Should not do anything if NDEBUG is defined
#define DCHECK(__CONDITION__) // Should not do anything unless the preprocessor constant DEBUG is non-zero
#define DNOT_REACHED() // Should not do anything unless the preprocessor constant DEBUG is non-zero
```
Advanced Example 1: Implementing HTTP Redirects