SDL_log.h 12 KB

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