Added an assert log category, and NSLog support on Mac OS X and iOS
authorSam Lantinga <slouken@libsdl.org>
Tue, 30 Oct 2012 12:30:02 -0700
changeset 66164f272256d172
parent 6615 d7a463bde4d7
child 6617 3a92812e0c91
Added an assert log category, and NSLog support on Mac OS X and iOS
include/SDL_log.h
src/SDL_log.c
src/video/cocoa/SDL_cocoavideo.m
src/video/uikit/SDL_uikitvideo.m
     1.1 --- a/include/SDL_log.h	Tue Oct 30 12:21:15 2012 -0700
     1.2 +++ b/include/SDL_log.h	Tue Oct 30 12:30:02 2012 -0700
     1.3 @@ -59,12 +59,14 @@
     1.4   *  \brief The predefined log categories
     1.5   *
     1.6   *  By default the application category is enabled at the INFO level,
     1.7 - *  and all other categories are enabled at the CRITICAL level.
     1.8 + *  the assert category is enabled at the WARN level, and all other
     1.9 + *  categories are enabled at the CRITICAL level.
    1.10   */
    1.11  enum
    1.12  {
    1.13      SDL_LOG_CATEGORY_APPLICATION,
    1.14      SDL_LOG_CATEGORY_ERROR,
    1.15 +    SDL_LOG_CATEGORY_ASSERT,
    1.16      SDL_LOG_CATEGORY_SYSTEM,
    1.17      SDL_LOG_CATEGORY_AUDIO,
    1.18      SDL_LOG_CATEGORY_VIDEO,
     2.1 --- a/src/SDL_log.c	Tue Oct 30 12:21:15 2012 -0700
     2.2 +++ b/src/SDL_log.c	Tue Oct 30 12:30:02 2012 -0700
     2.3 @@ -35,6 +35,7 @@
     2.4  #endif
     2.5  
     2.6  #define DEFAULT_PRIORITY                SDL_LOG_PRIORITY_CRITICAL
     2.7 +#define DEFAULT_ASSERT_PRIORITY         SDL_LOG_PRIORITY_WARN
     2.8  #define DEFAULT_APPLICATION_PRIORITY    SDL_LOG_PRIORITY_INFO
     2.9  
    2.10  typedef struct SDL_LogLevel
    2.11 @@ -50,8 +51,9 @@
    2.12                            const char *message);
    2.13  
    2.14  static SDL_LogLevel *SDL_loglevels;
    2.15 +static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
    2.16 +static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
    2.17  static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
    2.18 -static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
    2.19  static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
    2.20  static void *SDL_log_userdata = NULL;
    2.21  
    2.22 @@ -95,7 +97,9 @@
    2.23      for (entry = SDL_loglevels; entry; entry = entry->next) {
    2.24          entry->priority = priority;
    2.25      }
    2.26 -    SDL_application_priority = SDL_default_priority = priority;
    2.27 +    SDL_default_priority = priority;
    2.28 +    SDL_assert_priority = priority;
    2.29 +    SDL_application_priority = priority;
    2.30  }
    2.31  
    2.32  void
    2.33 @@ -133,6 +137,8 @@
    2.34  
    2.35      if (category == SDL_LOG_CATEGORY_APPLICATION) {
    2.36          return SDL_application_priority;
    2.37 +    } else if (category == SDL_LOG_CATEGORY_ASSERT) {
    2.38 +        return SDL_assert_priority;
    2.39      } else {
    2.40          return SDL_default_priority;
    2.41      }
    2.42 @@ -149,8 +155,9 @@
    2.43          SDL_free(entry);
    2.44      }
    2.45  
    2.46 +    SDL_default_priority = DEFAULT_PRIORITY;
    2.47 +    SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
    2.48      SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
    2.49 -    SDL_default_priority = DEFAULT_PRIORITY;
    2.50  }
    2.51  
    2.52  void
    2.53 @@ -302,6 +309,19 @@
    2.54          SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
    2.55          __android_log_write(SDL_android_priority[priority], tag, message);
    2.56      }
    2.57 +#elif defined(__APPLE__)
    2.58 +    extern void SDL_NSLog(const char *text);
    2.59 +    {
    2.60 +        char *text;
    2.61 +
    2.62 +        text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
    2.63 +        if (text) {
    2.64 +            SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
    2.65 +            SDL_NSLog(text);
    2.66 +            SDL_stack_free(text);
    2.67 +            return;
    2.68 +        }
    2.69 +    }
    2.70  #endif
    2.71  #if HAVE_STDIO_H
    2.72      fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
     3.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Tue Oct 30 12:21:15 2012 -0700
     3.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Tue Oct 30 12:30:02 2012 -0700
     3.3 @@ -218,6 +218,22 @@
     3.4  }
     3.5  
     3.6  /*
     3.7 + * Mac OS X log support.
     3.8 + *
     3.9 + * This doesn't really have aything to do with the interfaces of the SDL video
    3.10 + *  subsystem, but we need to stuff this into an Objective-C source code file.
    3.11 + */
    3.12 +
    3.13 +void SDL_NSLog(const char *text)
    3.14 +{
    3.15 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    3.16 +
    3.17 +    NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
    3.18 +
    3.19 +    [pool release];
    3.20 +}
    3.21 +
    3.22 +/*
    3.23   * Mac OS X assertion support.
    3.24   *
    3.25   * This doesn't really have aything to do with the interfaces of the SDL video
     4.1 --- a/src/video/uikit/SDL_uikitvideo.m	Tue Oct 30 12:21:15 2012 -0700
     4.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Tue Oct 30 12:30:02 2012 -0700
     4.3 @@ -129,6 +129,22 @@
     4.4      UIKit_QuitModes(_this);
     4.5  }
     4.6  
     4.7 +/*
     4.8 + * iOS log support.
     4.9 + *
    4.10 + * This doesn't really have aything to do with the interfaces of the SDL video
    4.11 + *  subsystem, but we need to stuff this into an Objective-C source code file.
    4.12 + */
    4.13 +
    4.14 +void SDL_NSLog(const char *text)
    4.15 +{
    4.16 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    4.17 +
    4.18 +    NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
    4.19 +
    4.20 +    [pool release];
    4.21 +}
    4.22 +
    4.23  #endif /* SDL_VIDEO_DRIVER_UIKIT */
    4.24  
    4.25  /* vi: set ts=4 sw=4 expandtab: */