SDL_log.h 11 KB

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