author | Andreas Schiffler <aschiffler@ferzkopp.net> |
Fri, 30 Nov 2012 23:25:34 -0800 | |
changeset 6717 | 2acd95060548 |
parent 6616 | 4f272256d172 |
child 6885 | 700f1b25f77f |
child 8377 | 3a7e8110201e |
permissions | -rw-r--r-- |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
/* |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
2 |
Simple DirectMedia Layer |
6138 | 3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
7 |
arising from the use of this software. |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
11 |
freely, subject to the following restrictions: |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
16 |
appreciated but is not required. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
18 |
misrepresented as being the original software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5348
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 |
*/ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
#include "SDL_config.h" |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
/* Simple log messages in SDL */ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
#include "SDL_log.h" |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
#if HAVE_STDIO_H |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
#include <stdio.h> |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
#endif |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
#if defined(__WIN32__) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
#include "core/windows/SDL_windows.h" |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
#elif defined(__ANDROID__) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
#include <android/log.h> |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
#endif |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 |
#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL |
6616
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
38 |
#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO |
6717
2acd95060548
Add log, assert and harness (partial) to test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
6616
diff
changeset
|
40 |
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
typedef struct SDL_LogLevel |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 |
int category; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
SDL_LogPriority priority; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 |
struct SDL_LogLevel *next; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
} SDL_LogLevel; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
|
5235
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
49 |
/* The default log output function */ |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
50 |
static void SDL_LogOutput(void *userdata, |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
51 |
int category, SDL_LogPriority priority, |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
52 |
const char *message); |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
53 |
|
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
static SDL_LogLevel *SDL_loglevels; |
6616
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
55 |
static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY; |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
56 |
static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 |
static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY; |
6717
2acd95060548
Add log, assert and harness (partial) to test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
6616
diff
changeset
|
58 |
static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY; |
5235
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
59 |
static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput; |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
60 |
static void *SDL_log_userdata = NULL; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = { |
5235
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
63 |
NULL, |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 |
"VERBOSE", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 |
"DEBUG", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
"INFO", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 |
"WARN", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
"ERROR", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 |
"CRITICAL" |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
}; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
#ifdef __ANDROID__ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
static const char *SDL_category_prefixes[SDL_LOG_CATEGORY_RESERVED1] = { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 |
"APP", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
"ERROR", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 |
"SYSTEM", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
"AUDIO", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
"VIDEO", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
"RENDER", |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 |
"INPUT" |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
}; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
ANDROID_LOG_VERBOSE, |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
ANDROID_LOG_DEBUG, |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
ANDROID_LOG_INFO, |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
ANDROID_LOG_WARN, |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 |
ANDROID_LOG_ERROR, |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
ANDROID_LOG_FATAL |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 |
}; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
#endif /* __ANDROID__ */ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 |
SDL_LogSetAllPriority(SDL_LogPriority priority) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 |
SDL_LogLevel *entry; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 |
for (entry = SDL_loglevels; entry; entry = entry->next) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 |
entry->priority = priority; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
} |
6616
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
102 |
SDL_default_priority = priority; |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
103 |
SDL_assert_priority = priority; |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
104 |
SDL_application_priority = priority; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
SDL_LogSetPriority(int category, SDL_LogPriority priority) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
SDL_LogLevel *entry; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
for (entry = SDL_loglevels; entry; entry = entry->next) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
if (entry->category == category) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
entry->priority = priority; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 |
return; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
/* Create a new entry */ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry)); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
if (entry) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 |
entry->category = category; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
entry->priority = priority; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 |
entry->next = SDL_loglevels; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
SDL_loglevels = entry; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
SDL_LogPriority |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 |
SDL_LogGetPriority(int category) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
SDL_LogLevel *entry; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
for (entry = SDL_loglevels; entry; entry = entry->next) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
if (entry->category == category) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 |
return entry->priority; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 |
|
6717
2acd95060548
Add log, assert and harness (partial) to test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
6616
diff
changeset
|
140 |
if (category == SDL_LOG_CATEGORY_TEST) { |
2acd95060548
Add log, assert and harness (partial) to test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
6616
diff
changeset
|
141 |
return SDL_test_priority; |
2acd95060548
Add log, assert and harness (partial) to test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
6616
diff
changeset
|
142 |
} else if (category == SDL_LOG_CATEGORY_APPLICATION) { |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 |
return SDL_application_priority; |
6616
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
144 |
} else if (category == SDL_LOG_CATEGORY_ASSERT) { |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
145 |
return SDL_assert_priority; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
} else { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 |
return SDL_default_priority; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
SDL_LogResetPriorities(void) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
SDL_LogLevel *entry; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 |
while (SDL_loglevels) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
entry = SDL_loglevels; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
SDL_loglevels = entry->next; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 |
SDL_free(entry); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
|
6616
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
162 |
SDL_default_priority = DEFAULT_PRIORITY; |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
163 |
SDL_assert_priority = DEFAULT_ASSERT_PRIORITY; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
SDL_application_priority = DEFAULT_APPLICATION_PRIORITY; |
6717
2acd95060548
Add log, assert and harness (partial) to test lib
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
6616
diff
changeset
|
165 |
SDL_test_priority = DEFAULT_TEST_PRIORITY; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 |
SDL_Log(const char *fmt, ...) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 |
va_list ap; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
va_start(ap, fmt); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 |
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 |
va_end(ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 |
SDL_LogVerbose(int category, const char *fmt, ...) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 |
va_list ap; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 |
va_start(ap, fmt); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 |
SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 |
va_end(ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 |
void |
5348
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
189 |
SDL_LogDebug(int category, const char *fmt, ...) |
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
190 |
{ |
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
191 |
va_list ap; |
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
192 |
|
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
193 |
va_start(ap, fmt); |
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
194 |
SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap); |
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
195 |
va_end(ap); |
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
196 |
} |
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
197 |
|
16202b090a63
Added missing log debug function
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
198 |
void |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 |
SDL_LogInfo(int category, const char *fmt, ...) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 |
va_list ap; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
va_start(ap, fmt); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 |
SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 |
va_end(ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 |
SDL_LogWarn(int category, const char *fmt, ...) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 |
va_list ap; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 |
va_start(ap, fmt); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 |
SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 |
va_end(ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 |
SDL_LogError(int category, const char *fmt, ...) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 |
va_list ap; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 |
va_start(ap, fmt); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
va_end(ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 |
SDL_LogCritical(int category, const char *fmt, ...) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 |
va_list ap; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
va_start(ap, fmt); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 |
SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 |
va_end(ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 |
va_list ap; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 |
va_start(ap, fmt); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 |
SDL_LogMessageV(category, priority, fmt, ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 |
va_end(ap); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 |
#ifdef __ANDROID__ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
static const char * |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 |
GetCategoryPrefix(int category) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 |
if (category < SDL_LOG_CATEGORY_RESERVED1) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 |
return SDL_category_prefixes[category]; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 |
if (category < SDL_LOG_CATEGORY_CUSTOM) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 |
return "RESERVED"; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 |
return "CUSTOM"; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 |
#endif /* __ANDROID__ */ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 |
void |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 |
SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 |
{ |
5223
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
265 |
char *message; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 |
|
5235
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
267 |
/* Nothing to do if we don't have an output function */ |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
268 |
if (!SDL_log_function) { |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
269 |
return; |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
270 |
} |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
271 |
|
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 |
/* Make sure we don't exceed array bounds */ |
6040 | 273 |
if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) { |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 |
return; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
/* See if we want to do anything with this message */ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 |
if (priority < SDL_LogGetPriority(category)) { |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 |
return; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 |
|
5223
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
282 |
message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); |
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
283 |
if (!message) { |
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
284 |
return; |
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
285 |
} |
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
286 |
SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap); |
5235
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
287 |
SDL_log_function(SDL_log_userdata, category, priority, message); |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
288 |
SDL_stack_free(message); |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
289 |
} |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 |
|
5235
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
291 |
static void |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
292 |
SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
293 |
const char *message) |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
294 |
{ |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 |
#if defined(__WIN32__) |
5223
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
296 |
/* Way too many allocations here, urgh */ |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 |
{ |
5223
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
298 |
char *output; |
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
299 |
size_t length; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 |
LPTSTR tstr; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 |
|
5223
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
302 |
length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1; |
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
303 |
output = SDL_stack_alloc(char, length); |
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
304 |
SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message); |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 |
tstr = WIN_UTF8ToString(output); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
OutputDebugString(tstr); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
SDL_free(tstr); |
5223
ab0d7cecc0f6
Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
5221
diff
changeset
|
308 |
SDL_stack_free(output); |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 |
#elif defined(__ANDROID__) |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 |
{ |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
char tag[32]; |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 |
SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category)); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 |
__android_log_write(SDL_android_priority[priority], tag, message); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 |
} |
6616
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
317 |
#elif defined(__APPLE__) |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
318 |
extern void SDL_NSLog(const char *text); |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
319 |
{ |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
320 |
char *text; |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
321 |
|
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
322 |
text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE); |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
323 |
if (text) { |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
324 |
SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message); |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
325 |
SDL_NSLog(text); |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
326 |
SDL_stack_free(text); |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
327 |
return; |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
328 |
} |
4f272256d172
Added an assert log category, and NSLog support on Mac OS X and iOS
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
329 |
} |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 |
#endif |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 |
#if HAVE_STDIO_H |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 |
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message); |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 |
#endif |
5235
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
334 |
} |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
335 |
|
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
336 |
void |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
337 |
SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata) |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
338 |
{ |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
339 |
if (callback) { |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
340 |
*callback = SDL_log_function; |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
341 |
} |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
342 |
if (userdata) { |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
343 |
*userdata = SDL_log_userdata; |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
344 |
} |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
345 |
} |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
346 |
|
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
347 |
void |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
348 |
SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata) |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
349 |
{ |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
350 |
SDL_log_function = callback; |
1e28342cb15d
Added a way to replace the default logging mechanism
Sam Lantinga <slouken@libsdl.org>
parents:
5223
diff
changeset
|
351 |
SDL_log_userdata = userdata; |
5221
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 |
} |
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 |
|
2ee8112bfc6b
Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 |
/* vi: set ts=4 sw=4 expandtab: */ |