SDL_log.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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. * # CategoryLog
  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_SetLogPriorities(SDL_LOG_PRIORITY_WARN);
  26. *
  27. * Here's where the messages go on different platforms:
  28. *
  29. * - Windows: debug output stream
  30. * - Android: log output
  31. * - Others: standard error output (stderr)
  32. */
  33. #ifndef SDL_log_h_
  34. #define SDL_log_h_
  35. #include <SDL3/SDL_stdinc.h>
  36. #include <SDL3/SDL_begin_code.h>
  37. /* Set up for C function definitions, even when using C++ */
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. * The predefined log categories
  43. *
  44. * By default the application category is enabled at the INFO level, the
  45. * assert category is enabled at the WARN level, test is enabled at the
  46. * VERBOSE level and all other categories are enabled at the ERROR level.
  47. *
  48. * \since This enum is available since SDL 3.0.0.
  49. */
  50. typedef enum SDL_LogCategory
  51. {
  52. SDL_LOG_CATEGORY_APPLICATION,
  53. SDL_LOG_CATEGORY_ERROR,
  54. SDL_LOG_CATEGORY_ASSERT,
  55. SDL_LOG_CATEGORY_SYSTEM,
  56. SDL_LOG_CATEGORY_AUDIO,
  57. SDL_LOG_CATEGORY_VIDEO,
  58. SDL_LOG_CATEGORY_RENDER,
  59. SDL_LOG_CATEGORY_INPUT,
  60. SDL_LOG_CATEGORY_TEST,
  61. /* Reserved for future SDL library use */
  62. SDL_LOG_CATEGORY_RESERVED1,
  63. SDL_LOG_CATEGORY_RESERVED2,
  64. SDL_LOG_CATEGORY_RESERVED3,
  65. SDL_LOG_CATEGORY_RESERVED4,
  66. SDL_LOG_CATEGORY_RESERVED5,
  67. SDL_LOG_CATEGORY_RESERVED6,
  68. SDL_LOG_CATEGORY_RESERVED7,
  69. SDL_LOG_CATEGORY_RESERVED8,
  70. SDL_LOG_CATEGORY_RESERVED9,
  71. SDL_LOG_CATEGORY_RESERVED10,
  72. /* Beyond this point is reserved for application use, e.g.
  73. enum {
  74. MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,
  75. MYAPP_CATEGORY_AWESOME2,
  76. MYAPP_CATEGORY_AWESOME3,
  77. ...
  78. };
  79. */
  80. SDL_LOG_CATEGORY_CUSTOM
  81. } SDL_LogCategory;
  82. /**
  83. * The predefined log priorities
  84. *
  85. * \since This enum is available since SDL 3.0.0.
  86. */
  87. typedef enum SDL_LogPriority
  88. {
  89. SDL_LOG_PRIORITY_VERBOSE = 1,
  90. SDL_LOG_PRIORITY_DEBUG,
  91. SDL_LOG_PRIORITY_INFO,
  92. SDL_LOG_PRIORITY_WARN,
  93. SDL_LOG_PRIORITY_ERROR,
  94. SDL_LOG_PRIORITY_CRITICAL,
  95. SDL_NUM_LOG_PRIORITIES
  96. } SDL_LogPriority;
  97. /**
  98. * Set the priority of all log categories.
  99. *
  100. * \param priority the SDL_LogPriority to assign.
  101. *
  102. * \since This function is available since SDL 3.0.0.
  103. *
  104. * \sa SDL_ResetLogPriorities
  105. * \sa SDL_SetLogPriority
  106. */
  107. extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriorities(SDL_LogPriority priority);
  108. /**
  109. * Set the priority of a particular log category.
  110. *
  111. * \param category the category to assign a priority to.
  112. * \param priority the SDL_LogPriority to assign.
  113. *
  114. * \since This function is available since SDL 3.0.0.
  115. *
  116. * \sa SDL_GetLogPriority
  117. * \sa SDL_ResetLogPriorities
  118. * \sa SDL_SetLogPriorities
  119. */
  120. extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category,
  121. SDL_LogPriority priority);
  122. /**
  123. * Get the priority of a particular log category.
  124. *
  125. * \param category the category to query.
  126. * \returns the SDL_LogPriority for the requested category.
  127. *
  128. * \since This function is available since SDL 3.0.0.
  129. *
  130. * \sa SDL_SetLogPriority
  131. */
  132. extern SDL_DECLSPEC SDL_LogPriority SDLCALL SDL_GetLogPriority(int category);
  133. /**
  134. * Reset all priorities to default.
  135. *
  136. * This is called by SDL_Quit().
  137. *
  138. * \since This function is available since SDL 3.0.0.
  139. *
  140. * \sa SDL_SetLogPriorities
  141. * \sa SDL_SetLogPriority
  142. */
  143. extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void);
  144. /**
  145. * Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.
  146. *
  147. * \param fmt a printf() style message format string.
  148. * \param ... additional parameters matching % tokens in the `fmt` string, if
  149. * any.
  150. *
  151. * \since This function is available since SDL 3.0.0.
  152. *
  153. * \sa SDL_LogCritical
  154. * \sa SDL_LogDebug
  155. * \sa SDL_LogError
  156. * \sa SDL_LogInfo
  157. * \sa SDL_LogMessage
  158. * \sa SDL_LogMessageV
  159. * \sa SDL_LogVerbose
  160. * \sa SDL_LogWarn
  161. */
  162. extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
  163. /**
  164. * Log a message with SDL_LOG_PRIORITY_VERBOSE.
  165. *
  166. * \param category the category of the message.
  167. * \param fmt a printf() style message format string.
  168. * \param ... additional parameters matching % tokens in the **fmt** string,
  169. * if any.
  170. *
  171. * \since This function is available since SDL 3.0.0.
  172. *
  173. * \sa SDL_Log
  174. * \sa SDL_LogCritical
  175. * \sa SDL_LogDebug
  176. * \sa SDL_LogError
  177. * \sa SDL_LogInfo
  178. * \sa SDL_LogMessage
  179. * \sa SDL_LogMessageV
  180. * \sa SDL_LogWarn
  181. */
  182. extern SDL_DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  183. /**
  184. * Log a message with SDL_LOG_PRIORITY_DEBUG.
  185. *
  186. * \param category the category of the message.
  187. * \param fmt a printf() style message format string.
  188. * \param ... additional parameters matching % tokens in the **fmt** string,
  189. * if any.
  190. *
  191. * \since This function is available since SDL 3.0.0.
  192. *
  193. * \sa SDL_Log
  194. * \sa SDL_LogCritical
  195. * \sa SDL_LogError
  196. * \sa SDL_LogInfo
  197. * \sa SDL_LogMessage
  198. * \sa SDL_LogMessageV
  199. * \sa SDL_LogVerbose
  200. * \sa SDL_LogWarn
  201. */
  202. extern SDL_DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  203. /**
  204. * Log a message with SDL_LOG_PRIORITY_INFO.
  205. *
  206. * \param category the category of the message.
  207. * \param fmt a printf() style message format string.
  208. * \param ... additional parameters matching % tokens in the **fmt** string,
  209. * if any.
  210. *
  211. * \since This function is available since SDL 3.0.0.
  212. *
  213. * \sa SDL_Log
  214. * \sa SDL_LogCritical
  215. * \sa SDL_LogDebug
  216. * \sa SDL_LogError
  217. * \sa SDL_LogMessage
  218. * \sa SDL_LogMessageV
  219. * \sa SDL_LogVerbose
  220. * \sa SDL_LogWarn
  221. */
  222. extern SDL_DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  223. /**
  224. * Log a message with SDL_LOG_PRIORITY_WARN.
  225. *
  226. * \param category the category of the message.
  227. * \param fmt a printf() style message format string.
  228. * \param ... additional parameters matching % tokens in the **fmt** string,
  229. * if any.
  230. *
  231. * \since This function is available since SDL 3.0.0.
  232. *
  233. * \sa SDL_Log
  234. * \sa SDL_LogCritical
  235. * \sa SDL_LogDebug
  236. * \sa SDL_LogError
  237. * \sa SDL_LogInfo
  238. * \sa SDL_LogMessage
  239. * \sa SDL_LogMessageV
  240. * \sa SDL_LogVerbose
  241. */
  242. extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  243. /**
  244. * Log a message with SDL_LOG_PRIORITY_ERROR.
  245. *
  246. * \param category the category of the message.
  247. * \param fmt a printf() style message format string.
  248. * \param ... additional parameters matching % tokens in the **fmt** string,
  249. * if any.
  250. *
  251. * \since This function is available since SDL 3.0.0.
  252. *
  253. * \sa SDL_Log
  254. * \sa SDL_LogCritical
  255. * \sa SDL_LogDebug
  256. * \sa SDL_LogInfo
  257. * \sa SDL_LogMessage
  258. * \sa SDL_LogMessageV
  259. * \sa SDL_LogVerbose
  260. * \sa SDL_LogWarn
  261. */
  262. extern SDL_DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  263. /**
  264. * Log a message with SDL_LOG_PRIORITY_CRITICAL.
  265. *
  266. * \param category the category 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. * \since This function is available since SDL 3.0.0.
  272. *
  273. * \sa SDL_Log
  274. * \sa SDL_LogDebug
  275. * \sa SDL_LogError
  276. * \sa SDL_LogInfo
  277. * \sa SDL_LogMessage
  278. * \sa SDL_LogMessageV
  279. * \sa SDL_LogVerbose
  280. * \sa SDL_LogWarn
  281. */
  282. extern SDL_DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  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 ... additional parameters matching % tokens in the **fmt** string,
  290. * if any.
  291. *
  292. * \since This function is available since SDL 3.0.0.
  293. *
  294. * \sa SDL_Log
  295. * \sa SDL_LogCritical
  296. * \sa SDL_LogDebug
  297. * \sa SDL_LogError
  298. * \sa SDL_LogInfo
  299. * \sa SDL_LogMessageV
  300. * \sa SDL_LogVerbose
  301. * \sa SDL_LogWarn
  302. */
  303. extern SDL_DECLSPEC void SDLCALL SDL_LogMessage(int category,
  304. SDL_LogPriority priority,
  305. SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
  306. /**
  307. * Log a message with the specified category and priority.
  308. *
  309. * \param category the category of the message.
  310. * \param priority the priority of the message.
  311. * \param fmt a printf() style message format string.
  312. * \param ap a variable argument list.
  313. *
  314. * \since This function is available since SDL 3.0.0.
  315. *
  316. * \sa SDL_Log
  317. * \sa SDL_LogCritical
  318. * \sa SDL_LogDebug
  319. * \sa SDL_LogError
  320. * \sa SDL_LogInfo
  321. * \sa SDL_LogMessage
  322. * \sa SDL_LogVerbose
  323. * \sa SDL_LogWarn
  324. */
  325. extern SDL_DECLSPEC void SDLCALL SDL_LogMessageV(int category,
  326. SDL_LogPriority priority,
  327. SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);
  328. /**
  329. * The prototype for the log output callback function.
  330. *
  331. * This function is called by SDL when there is new text to be logged.
  332. *
  333. * \param userdata what was passed as `userdata` to
  334. * SDL_SetLogOutputFunction().
  335. * \param category the category of the message.
  336. * \param priority the priority of the message.
  337. * \param message the message being output.
  338. *
  339. * \since This datatype is available since SDL 3.0.0.
  340. */
  341. typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);
  342. /**
  343. * Get the current log output function.
  344. *
  345. * \param callback an SDL_LogOutputFunction filled in with the current log
  346. * callback.
  347. * \param userdata a pointer filled in with the pointer that is passed to
  348. * `callback`.
  349. *
  350. * \since This function is available since SDL 3.0.0.
  351. *
  352. * \sa SDL_SetLogOutputFunction
  353. */
  354. extern SDL_DECLSPEC void SDLCALL SDL_GetLogOutputFunction(SDL_LogOutputFunction *callback, void **userdata);
  355. /**
  356. * Replace the default log output function with one of your own.
  357. *
  358. * \param callback an SDL_LogOutputFunction to call instead of the default.
  359. * \param userdata a pointer that is passed to `callback`.
  360. *
  361. * \since This function is available since SDL 3.0.0.
  362. *
  363. * \sa SDL_GetLogOutputFunction
  364. */
  365. extern SDL_DECLSPEC void SDLCALL SDL_SetLogOutputFunction(SDL_LogOutputFunction callback, void *userdata);
  366. /* Ends C function definitions when using C++ */
  367. #ifdef __cplusplus
  368. }
  369. #endif
  370. #include <SDL3/SDL_close_code.h>
  371. #endif /* SDL_log_h_ */