SDL_log.h 13 KB

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