Added an assert log category, and NSLog support on Mac OS X and iOS
This commit is contained in:
parent
57f18e2fc2
commit
8850825033
4 changed files with 58 additions and 4 deletions
|
@ -59,12 +59,14 @@ extern "C" {
|
||||||
* \brief The predefined log categories
|
* \brief The predefined log categories
|
||||||
*
|
*
|
||||||
* By default the application category is enabled at the INFO level,
|
* By default the application category is enabled at the INFO level,
|
||||||
* and all other categories are enabled at the CRITICAL level.
|
* the assert category is enabled at the WARN level, and all other
|
||||||
|
* categories are enabled at the CRITICAL level.
|
||||||
*/
|
*/
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LOG_CATEGORY_APPLICATION,
|
||||||
SDL_LOG_CATEGORY_ERROR,
|
SDL_LOG_CATEGORY_ERROR,
|
||||||
|
SDL_LOG_CATEGORY_ASSERT,
|
||||||
SDL_LOG_CATEGORY_SYSTEM,
|
SDL_LOG_CATEGORY_SYSTEM,
|
||||||
SDL_LOG_CATEGORY_AUDIO,
|
SDL_LOG_CATEGORY_AUDIO,
|
||||||
SDL_LOG_CATEGORY_VIDEO,
|
SDL_LOG_CATEGORY_VIDEO,
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
|
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
|
||||||
|
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
|
||||||
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
|
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
|
||||||
|
|
||||||
typedef struct SDL_LogLevel
|
typedef struct SDL_LogLevel
|
||||||
|
@ -50,8 +51,9 @@ static void SDL_LogOutput(void *userdata,
|
||||||
const char *message);
|
const char *message);
|
||||||
|
|
||||||
static SDL_LogLevel *SDL_loglevels;
|
static SDL_LogLevel *SDL_loglevels;
|
||||||
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
|
||||||
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
|
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
|
||||||
|
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
|
||||||
|
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
||||||
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
|
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
|
||||||
static void *SDL_log_userdata = NULL;
|
static void *SDL_log_userdata = NULL;
|
||||||
|
|
||||||
|
@ -95,7 +97,9 @@ SDL_LogSetAllPriority(SDL_LogPriority priority)
|
||||||
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
for (entry = SDL_loglevels; entry; entry = entry->next) {
|
||||||
entry->priority = priority;
|
entry->priority = priority;
|
||||||
}
|
}
|
||||||
SDL_application_priority = SDL_default_priority = priority;
|
SDL_default_priority = priority;
|
||||||
|
SDL_assert_priority = priority;
|
||||||
|
SDL_application_priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -133,6 +137,8 @@ SDL_LogGetPriority(int category)
|
||||||
|
|
||||||
if (category == SDL_LOG_CATEGORY_APPLICATION) {
|
if (category == SDL_LOG_CATEGORY_APPLICATION) {
|
||||||
return SDL_application_priority;
|
return SDL_application_priority;
|
||||||
|
} else if (category == SDL_LOG_CATEGORY_ASSERT) {
|
||||||
|
return SDL_assert_priority;
|
||||||
} else {
|
} else {
|
||||||
return SDL_default_priority;
|
return SDL_default_priority;
|
||||||
}
|
}
|
||||||
|
@ -149,8 +155,9 @@ SDL_LogResetPriorities(void)
|
||||||
SDL_free(entry);
|
SDL_free(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
|
||||||
SDL_default_priority = DEFAULT_PRIORITY;
|
SDL_default_priority = DEFAULT_PRIORITY;
|
||||||
|
SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
|
||||||
|
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -302,6 +309,19 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
|
||||||
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
|
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
|
||||||
__android_log_write(SDL_android_priority[priority], tag, message);
|
__android_log_write(SDL_android_priority[priority], tag, message);
|
||||||
}
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
extern void SDL_NSLog(const char *text);
|
||||||
|
{
|
||||||
|
char *text;
|
||||||
|
|
||||||
|
text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
|
||||||
|
if (text) {
|
||||||
|
SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
|
||||||
|
SDL_NSLog(text);
|
||||||
|
SDL_stack_free(text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_STDIO_H
|
#if HAVE_STDIO_H
|
||||||
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||||
|
|
|
@ -217,6 +217,22 @@ Cocoa_CreateImage(SDL_Surface * surface)
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mac OS X log support.
|
||||||
|
*
|
||||||
|
* This doesn't really have aything to do with the interfaces of the SDL video
|
||||||
|
* subsystem, but we need to stuff this into an Objective-C source code file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SDL_NSLog(const char *text)
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mac OS X assertion support.
|
* Mac OS X assertion support.
|
||||||
*
|
*
|
||||||
|
|
|
@ -129,6 +129,22 @@ UIKit_VideoQuit(_THIS)
|
||||||
UIKit_QuitModes(_this);
|
UIKit_QuitModes(_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iOS log support.
|
||||||
|
*
|
||||||
|
* This doesn't really have aything to do with the interfaces of the SDL video
|
||||||
|
* subsystem, but we need to stuff this into an Objective-C source code file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SDL_NSLog(const char *text)
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
|
NSLog(@"%@", [[NSString alloc] initWithUTF8String:text]);
|
||||||
|
|
||||||
|
[pool release];
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue