annotate src/SDL_log.c @ 5229:2178ffe17222

Added function SDL_RenderSetClipRect()
author Sam Lantinga <slouken@libsdl.org>
date Mon, 07 Feb 2011 20:06:26 -0800
parents ab0d7cecc0f6
children 1e28342cb15d
rev   line source
5226
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /* Simple log messages in SDL */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "SDL_log.h"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #if HAVE_STDIO_H
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include <stdio.h>
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #endif
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #if defined(__WIN32__)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include "core/windows/SDL_windows.h"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #elif defined(__ANDROID__)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <android/log.h>
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #endif
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 typedef struct SDL_LogLevel
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 int category;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 SDL_LogPriority priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 struct SDL_LogLevel *next;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 } SDL_LogLevel;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 static SDL_LogLevel *SDL_loglevels;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 "VERBOSE",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 "DEBUG",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 "INFO",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 "WARN",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 "ERROR",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 "CRITICAL"
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 };
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 #ifdef __ANDROID__
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 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
63 "APP",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 "ERROR",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 "SYSTEM",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 "AUDIO",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 "VIDEO",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 "RENDER",
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 "INPUT"
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 static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 ANDROID_LOG_VERBOSE,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 ANDROID_LOG_DEBUG,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 ANDROID_LOG_INFO,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 ANDROID_LOG_WARN,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 ANDROID_LOG_ERROR,
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 ANDROID_LOG_FATAL
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 };
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 #endif /* __ANDROID__ */
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 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 SDL_LogSetAllPriority(SDL_LogPriority priority)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 SDL_LogLevel *entry;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 for (entry = SDL_loglevels; entry; entry = entry->next) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 entry->priority = priority;
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 SDL_application_priority = SDL_default_priority = priority;
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_LogSetPriority(int category, 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 if (entry->category == category) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 entry->priority = priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 return;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 }
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 /* Create a new entry */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 if (entry) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 entry->category = category;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 entry->priority = priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 entry->next = SDL_loglevels;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 SDL_loglevels = entry;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 SDL_LogPriority
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 SDL_LogGetPriority(int category)
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 SDL_LogLevel *entry;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 for (entry = SDL_loglevels; entry; entry = entry->next) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 if (entry->category == category) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 return entry->priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 }
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 if (category == SDL_LOG_CATEGORY_APPLICATION) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 return SDL_application_priority;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 } else {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 return SDL_default_priority;
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 }
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 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 SDL_LogResetPriorities(void)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 SDL_LogLevel *entry;
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 while (SDL_loglevels) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 entry = SDL_loglevels;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 SDL_loglevels = entry->next;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 SDL_free(entry);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 SDL_default_priority = DEFAULT_PRIORITY;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 }
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 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 SDL_Log(const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 va_list ap;
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 va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 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
156 va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 SDL_LogVerbose(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 va_end(ap);
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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 SDL_LogInfo(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 va_end(ap);
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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 SDL_LogWarn(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 va_end(ap);
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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 SDL_LogError(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 va_end(ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 SDL_LogCritical(int category, const char *fmt, ...)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 va_end(ap);
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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 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
211 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 va_list ap;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 va_start(ap, fmt);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 SDL_LogMessageV(category, priority, fmt, ap);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 va_end(ap);
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
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 #ifdef __ANDROID__
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 static const char *
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 GetCategoryPrefix(int category)
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 if (category < SDL_LOG_CATEGORY_RESERVED1) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 return SDL_category_prefixes[category];
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 if (category < SDL_LOG_CATEGORY_CUSTOM) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 return "RESERVED";
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 return "CUSTOM";
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 #endif /* __ANDROID__ */
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 void
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 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
235 {
5228
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
236 char *message;
5226
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 /* Make sure we don't exceed array bounds */
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 if (priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 return;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 }
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 /* 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
244 if (priority < SDL_LogGetPriority(category)) {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 return;
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
5228
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
248 message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
249 if (!message) {
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
250 return;
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
251 }
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
252 SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
5226
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 #if defined(__WIN32__)
5228
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
255 /* Way too many allocations here, urgh */
5226
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 {
5228
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
257 char *output;
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
258 size_t length;
5226
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 LPTSTR tstr;
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
5228
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
261 length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1;
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
262 output = SDL_stack_alloc(char, length);
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
263 SDL_snprintf(output, length, "%s: %s", SDL_priority_prefixes[priority], message);
5226
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 tstr = WIN_UTF8ToString(output);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 OutputDebugString(tstr);
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 SDL_free(tstr);
5228
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
267 SDL_stack_free(output);
5226
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 #elif defined(__ANDROID__)
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 {
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 char tag[32];
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 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
274 __android_log_write(SDL_android_priority[priority], tag, message);
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 #endif
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 #if HAVE_STDIO_H
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 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
279 #endif
5228
ab0d7cecc0f6 Fixed stack overflow on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 5226
diff changeset
280 SDL_stack_free(message);
5226
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 }
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282
2ee8112bfc6b Added a simple log message API
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 /* vi: set ts=4 sw=4 expandtab: */