SDL_log.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_log.h
  20. *
  21. * Simple log messages with categories and priorities.
  22. *
  23. * By default logs are quiet, but if you're debugging SDL you might want:
  24. *
  25. * SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
  26. *
  27. * Here's where the messages go on different platforms:
  28. * Windows: debug output stream
  29. * Android: log output
  30. * Others: standard error output (stderr)
  31. */
  32. #ifndef SDL_log_h_
  33. #define SDL_log_h_
  34. #include "SDL_stdinc.h"
  35. #include "begin_code.h"
  36. /* Set up for C function definitions, even when using C++ */
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /**
  41. * \brief The maximum size of a log message
  42. *
  43. * Messages longer than the maximum size will be truncated
  44. */
  45. #define SDL_MAX_LOG_MESSAGE 4096
  46. /**
  47. * \brief The predefined log categories
  48. *
  49. * By default the application category is enabled at the INFO level,
  50. * the assert category is enabled at the WARN level, test is enabled
  51. * at the VERBOSE level and all other categories are enabled at the
  52. * CRITICAL level.
  53. */
  54. typedef enum
  55. {
  56. SDL_LOG_CATEGORY_APPLICATION,
  57. SDL_LOG_CATEGORY_ERROR,
  58. SDL_LOG_CATEGORY_ASSERT,
  59. SDL_LOG_CATEGORY_SYSTEM,
  60. SDL_LOG_CATEGORY_AUDIO,
  61. SDL_LOG_CATEGORY_VIDEO,
  62. SDL_LOG_CATEGORY_RENDER,
  63. SDL_LOG_CATEGORY_INPUT,
  64. SDL_LOG_CATEGORY_TEST,
  65. /* Reserved for future SDL library use */
  66. SDL_LOG_CATEGORY_RESERVED1,
  67. SDL_LOG_CATEGORY_RESERVED2,
  68. SDL_LOG_CATEGORY_RESERVED3,
  69. SDL_LOG_CATEGORY_RESERVED4,
  70. SDL_LOG_CATEGORY_RESERVED5,
  71. SDL_LOG_CATEGORY_RESERVED6,
  72. SDL_LOG_CATEGORY_RESERVED7,
  73. SDL_LOG_CATEGORY_RESERVED8,
  74. SDL_LOG_CATEGORY_RESERVED9,
  75. SDL_LOG_CATEGORY_RESERVED10,
  76. /* Beyond this point is reserved for application use, e.g.
  77. enum {
  78. MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,
  79. MYAPP_CATEGORY_AWESOME2,
  80. MYAPP_CATEGORY_AWESOME3,
  81. ...
  82. };
  83. */
  84. SDL_LOG_CATEGORY_CUSTOM
  85. } SDL_LogCategory;
  86. /**
  87. * \brief The predefined log priorities
  88. */
  89. typedef enum
  90. {
  91. SDL_LOG_PRIORITY_VERBOSE = 1,
  92. SDL_LOG_PRIORITY_DEBUG,
  93. SDL_LOG_PRIORITY_INFO,
  94. SDL_LOG_PRIORITY_WARN,
  95. SDL_LOG_PRIORITY_ERROR,
  96. SDL_LOG_PRIORITY_CRITICAL,
  97. SDL_NUM_LOG_PRIORITIES
  98. } SDL_LogPriority;
  99. /**
  100. * Set the priority of all log categories.
  101. *
  102. * \param priority the SDL_LogPriority to assign
  103. *
  104. * \sa SDL_LogSetPriority
  105. */
  106. extern DECLSPEC void SDLCALL SDL_LogSetAllPriority(SDL_LogPriority priority);
  107. /**
  108. * Set the priority of a particular log category.
  109. *
  110. * \param category the category to assign a priority to
  111. * \param priority the SDL_LogPriority to assign
  112. *
  113. * \sa SDL_LogGetPriority
  114. * \sa SDL_LogSetAllPriority
  115. */
  116. extern DECLSPEC void SDLCALL SDL_LogSetPriority(int category,
  117. SDL_LogPriority priority);
  118. /**
  119. * Get the priority of a particular log category.
  120. *
  121. * \param category the category to query
  122. * \returns the SDL_LogPriority for the requested category
  123. *
  124. * \sa SDL_LogSetPriority
  125. */
  126. extern DECLSPEC SDL_LogPriority SDLCALL SDL_LogGetPriority(int category);
  127. /**
  128. * Reset all priorities to default.
  129. *
  130. * This is called by SDL_Quit().
  131. *
  132. * \sa SDL_LogSetAllPriority
  133. * \sa SDL_LogSetPriority
  134. */
  135. extern DECLSPEC void SDLCALL SDL_LogResetPriorities(void);
  136. /**
  137. * Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.
  138. *
  139. * = * \param fmt a printf() style message format string
  140. *
  141. * \param ... additional parameters matching % tokens in the `fmt` string, if
  142. * any
  143. *
  144. * \sa SDL_LogCritical
  145. * \sa SDL_LogDebug
  146. * \sa SDL_LogError
  147. * \sa SDL_LogInfo
  148. * \sa SDL_LogMessage
  149. * \sa SDL_LogMessageV
  150. * \sa SDL_LogVerbose
  151. * \sa SDL_LogWarn
  152. */
  153. extern DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
  154. /**
  155. * Log a message with SDL_LOG_PRIORITY_VERBOSE.
  156. *
  157. * \param category the category of the message
  158. * \param fmt a printf() style message format string
  159. * \param ... additional parameters matching % tokens in the **fmt** string,
  160. * if any
  161. *
  162. * \sa SDL_Log
  163. * \sa SDL_LogCritical
  164. * \sa SDL_LogDebug
  165. * \sa SDL_LogError
  166. * \sa SDL_LogInfo
  167. * \sa SDL_LogMessage
  168. * \sa SDL_LogMessageV
  169. * \sa SDL_LogWarn
  170. */
  171. extern DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  172. /**
  173. * Log a message with SDL_LOG_PRIORITY_DEBUG.
  174. *
  175. * \param category the category of the message
  176. * \param fmt a printf() style message format string
  177. * \param ... additional parameters matching % tokens in the **fmt** string,
  178. * if any
  179. *
  180. * \sa SDL_Log
  181. * \sa SDL_LogCritical
  182. * \sa SDL_LogError
  183. * \sa SDL_LogInfo
  184. * \sa SDL_LogMessage
  185. * \sa SDL_LogMessageV
  186. * \sa SDL_LogVerbose
  187. * \sa SDL_LogWarn
  188. */
  189. extern DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  190. /**
  191. * Log a message with SDL_LOG_PRIORITY_INFO.
  192. *
  193. * \param category the category of the message
  194. * \param fmt a printf() style message format string
  195. * \param ... additional parameters matching % tokens in the **fmt** string,
  196. * if any
  197. *
  198. * \sa SDL_Log
  199. * \sa SDL_LogCritical
  200. * \sa SDL_LogDebug
  201. * \sa SDL_LogError
  202. * \sa SDL_LogMessage
  203. * \sa SDL_LogMessageV
  204. * \sa SDL_LogVerbose
  205. * \sa SDL_LogWarn
  206. */
  207. extern DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  208. /**
  209. * Log a message with SDL_LOG_PRIORITY_WARN.
  210. *
  211. * \param category the category of the message
  212. * \param fmt a printf() style message format string
  213. * \param ... additional parameters matching % tokens in the **fmt** string,
  214. * if any
  215. *
  216. * \sa SDL_Log
  217. * \sa SDL_LogCritical
  218. * \sa SDL_LogDebug
  219. * \sa SDL_LogError
  220. * \sa SDL_LogInfo
  221. * \sa SDL_LogMessage
  222. * \sa SDL_LogMessageV
  223. * \sa SDL_LogVerbose
  224. */
  225. extern DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  226. /**
  227. * Log a message with SDL_LOG_PRIORITY_ERROR.
  228. *
  229. * \param category the category of the message
  230. * \param fmt a printf() style message format string
  231. * \param ... additional parameters matching % tokens in the **fmt** string,
  232. * if any
  233. *
  234. * \sa SDL_Log
  235. * \sa SDL_LogCritical
  236. * \sa SDL_LogDebug
  237. * \sa SDL_LogInfo
  238. * \sa SDL_LogMessage
  239. * \sa SDL_LogMessageV
  240. * \sa SDL_LogVerbose
  241. * \sa SDL_LogWarn
  242. */
  243. extern DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  244. /**
  245. * Log a message with SDL_LOG_PRIORITY_CRITICAL.
  246. *
  247. * \param category the category of the message
  248. * \param fmt a printf() style message format string
  249. * \param ... additional parameters matching % tokens in the **fmt** string,
  250. * if any
  251. *
  252. * \sa SDL_Log
  253. * \sa SDL_LogDebug
  254. * \sa SDL_LogError
  255. * \sa SDL_LogInfo
  256. * \sa SDL_LogMessage
  257. * \sa SDL_LogMessageV
  258. * \sa SDL_LogVerbose
  259. * \sa SDL_LogWarn
  260. */
  261. extern DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  262. /**
  263. * Log a message with the specified category and priority.
  264. *
  265. * \param category the category of the message
  266. * \param priority the priority of the message
  267. * \param fmt a printf() style message format string
  268. * \param ... additional parameters matching % tokens in the **fmt** string,
  269. * if any
  270. *
  271. * \sa SDL_Log
  272. * \sa SDL_LogCritical
  273. * \sa SDL_LogDebug
  274. * \sa SDL_LogError
  275. * \sa SDL_LogInfo
  276. * \sa SDL_LogMessageV
  277. * \sa SDL_LogVerbose
  278. * \sa SDL_LogWarn
  279. */
  280. extern DECLSPEC void SDLCALL SDL_LogMessage(int category,
  281. SDL_LogPriority priority,
  282. SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
  283. /**
  284. * Log a message with the specified category and priority.
  285. *
  286. * \param category the category of the message
  287. * \param priority the priority of the message
  288. * \param fmt a printf() style message format string
  289. * \param ap a variable argument list
  290. *
  291. * \since This function is available since SDL 2.0.0.
  292. *
  293. * \sa SDL_Log
  294. * \sa SDL_LogCritical
  295. * \sa SDL_LogDebug
  296. * \sa SDL_LogError
  297. * \sa SDL_LogInfo
  298. * \sa SDL_LogMessage
  299. * \sa SDL_LogVerbose
  300. * \sa SDL_LogWarn
  301. */
  302. extern DECLSPEC void SDLCALL SDL_LogMessageV(int category,
  303. SDL_LogPriority priority,
  304. const char *fmt, va_list ap);
  305. /**
  306. * The prototype for the log output callback function.
  307. *
  308. * This function is called by SDL when there is new text to be logged.
  309. *
  310. * \param userdata what was passed as `userdata` to SDL_LogSetOutputFunction()
  311. * \param category the category of the message
  312. * \param priority the priority of the message
  313. * \param message the message being output
  314. */
  315. typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);
  316. /**
  317. * Get the current log output function.
  318. *
  319. * \param callback an SDL_LogOutputFunction filled in with the current log
  320. * callback
  321. * \param userdata a pointer filled in with the pointer that is passed to
  322. * `callback`
  323. *
  324. * \sa SDL_LogSetOutputFunction
  325. */
  326. extern DECLSPEC void SDLCALL SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata);
  327. /**
  328. * Replace the default log output function with one of your own.
  329. *
  330. * \param callback an SDL_LogOutputFunction to call instead of the default
  331. * \param userdata a pointer that is passed to `callback`
  332. *
  333. * \sa SDL_LogGetOutputFunction
  334. */
  335. extern DECLSPEC void SDLCALL SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata);
  336. /* Ends C function definitions when using C++ */
  337. #ifdef __cplusplus
  338. }
  339. #endif
  340. #include "close_code.h"
  341. #endif /* SDL_log_h_ */
  342. /* vi: set ts=4 sw=4 expandtab: */