diff --git a/GCDWebServer.podspec b/GCDWebServer.podspec index 86a3496..a4aadae 100644 --- a/GCDWebServer.podspec +++ b/GCDWebServer.podspec @@ -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| diff --git a/GCDWebServer.xcodeproj/project.pbxproj b/GCDWebServer.xcodeproj/project.pbxproj index 03bc829..fe9e1e6 100644 --- a/GCDWebServer.xcodeproj/project.pbxproj +++ b/GCDWebServer.xcodeproj/project.pbxproj @@ -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"; diff --git a/GCDWebServer/Core/GCDWebServer.h b/GCDWebServer/Core/GCDWebServer.h index 4b23260..f896750 100644 --- a/GCDWebServer/Core/GCDWebServer.h +++ b/GCDWebServer/Core/GCDWebServer.h @@ -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; diff --git a/GCDWebServer/Core/GCDWebServer.m b/GCDWebServer/Core/GCDWebServer.m index 5e06936..749a938 100644 --- a/GCDWebServer/Core/GCDWebServer.m +++ b/GCDWebServer/Core/GCDWebServer.m @@ -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"]]; diff --git a/GCDWebServer/Core/GCDWebServerPrivate.h b/GCDWebServer/Core/GCDWebServerPrivate.h index 7fe57fc..03e8c9f 100644 --- a/GCDWebServer/Core/GCDWebServerPrivate.h +++ b/GCDWebServer/Core/GCDWebServerPrivate.h @@ -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 diff --git a/Mac/main.m b/Mac/main.m index cabe495..baf297d 100644 --- a/Mac/main.m +++ b/Mac/main.m @@ -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, "\n\n", [testDirectory UTF8String]); diff --git a/README.md b/README.md index b21cf79..d7df93c 100644 --- a/README.md +++ b/README.md @@ -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