SDL_log.h 12 KB

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