1
0

SDL_log.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 and gpu categories are enabled at the INFO
  68. * level, the assert category is enabled at the WARN level, test is enabled at
  69. * the VERBOSE level and all other categories are enabled at the ERROR level.
  70. *
  71. * \since This enum is available since SDL 3.1.3.
  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. SDL_LOG_CATEGORY_GPU,
  85. /* Reserved for future SDL library use */
  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.1.3.
  109. */
  110. typedef enum SDL_LogPriority
  111. {
  112. SDL_LOG_PRIORITY_INVALID,
  113. SDL_LOG_PRIORITY_TRACE,
  114. SDL_LOG_PRIORITY_VERBOSE,
  115. SDL_LOG_PRIORITY_DEBUG,
  116. SDL_LOG_PRIORITY_INFO,
  117. SDL_LOG_PRIORITY_WARN,
  118. SDL_LOG_PRIORITY_ERROR,
  119. SDL_LOG_PRIORITY_CRITICAL,
  120. SDL_LOG_PRIORITY_COUNT
  121. } SDL_LogPriority;
  122. /**
  123. * Set the priority of all log categories.
  124. *
  125. * \param priority the SDL_LogPriority to assign.
  126. *
  127. * \threadsafety It is safe to call this function from any thread.
  128. *
  129. * \since This function is available since SDL 3.1.3.
  130. *
  131. * \sa SDL_ResetLogPriorities
  132. * \sa SDL_SetLogPriority
  133. */
  134. extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriorities(SDL_LogPriority priority);
  135. /**
  136. * Set the priority of a particular log category.
  137. *
  138. * \param category the category to assign a priority to.
  139. * \param priority the SDL_LogPriority to assign.
  140. *
  141. * \threadsafety It is safe to call this function from any thread.
  142. *
  143. * \since This function is available since SDL 3.1.3.
  144. *
  145. * \sa SDL_GetLogPriority
  146. * \sa SDL_ResetLogPriorities
  147. * \sa SDL_SetLogPriorities
  148. */
  149. extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category, SDL_LogPriority priority);
  150. /**
  151. * Get the priority of a particular log category.
  152. *
  153. * \param category the category to query.
  154. * \returns the SDL_LogPriority for the requested category.
  155. *
  156. * \threadsafety It is safe to call this function from any thread.
  157. *
  158. * \since This function is available since SDL 3.1.3.
  159. *
  160. * \sa SDL_SetLogPriority
  161. */
  162. extern SDL_DECLSPEC SDL_LogPriority SDLCALL SDL_GetLogPriority(int category);
  163. /**
  164. * Reset all priorities to default.
  165. *
  166. * This is called by SDL_Quit().
  167. *
  168. * \threadsafety It is safe to call this function from any thread.
  169. *
  170. * \since This function is available since SDL 3.1.3.
  171. *
  172. * \sa SDL_SetLogPriorities
  173. * \sa SDL_SetLogPriority
  174. */
  175. extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void);
  176. /**
  177. * Set the text prepended to log messages of a given priority.
  178. *
  179. * By default SDL_LOG_PRIORITY_INFO and below have no prefix, and
  180. * SDL_LOG_PRIORITY_WARN and higher have a prefix showing their priority, e.g.
  181. * "WARNING: ".
  182. *
  183. * \param priority the SDL_LogPriority to modify.
  184. * \param prefix the prefix to use for that log priority, or NULL to use no
  185. * prefix.
  186. * \returns true on success or false on failure; call SDL_GetError() for more
  187. * information.
  188. *
  189. * \threadsafety It is safe to call this function from any thread.
  190. *
  191. * \since This function is available since SDL 3.1.3.
  192. *
  193. * \sa SDL_SetLogPriorities
  194. * \sa SDL_SetLogPriority
  195. */
  196. extern SDL_DECLSPEC bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix);
  197. /**
  198. * Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.
  199. *
  200. * \param fmt a printf() style message format string.
  201. * \param ... additional parameters matching % tokens in the `fmt` string, if
  202. * any.
  203. *
  204. * \threadsafety It is safe to call this function from any thread.
  205. *
  206. * \since This function is available since SDL 3.1.3.
  207. *
  208. * \sa SDL_LogCritical
  209. * \sa SDL_LogDebug
  210. * \sa SDL_LogError
  211. * \sa SDL_LogInfo
  212. * \sa SDL_LogMessage
  213. * \sa SDL_LogMessageV
  214. * \sa SDL_LogTrace
  215. * \sa SDL_LogVerbose
  216. * \sa SDL_LogWarn
  217. */
  218. extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
  219. /**
  220. * Log a message with SDL_LOG_PRIORITY_TRACE.
  221. *
  222. * \param category the category of the message.
  223. * \param fmt a printf() style message format string.
  224. * \param ... additional parameters matching % tokens in the **fmt** string,
  225. * if any.
  226. *
  227. * \threadsafety It is safe to call this function from any thread.
  228. *
  229. * \since This function is available since SDL 3.1.3.
  230. *
  231. * \sa SDL_Log
  232. * \sa SDL_LogCritical
  233. * \sa SDL_LogDebug
  234. * \sa SDL_LogError
  235. * \sa SDL_LogInfo
  236. * \sa SDL_LogMessage
  237. * \sa SDL_LogMessageV
  238. * \sa SDL_LogTrace
  239. * \sa SDL_LogVerbose
  240. * \sa SDL_LogWarn
  241. */
  242. extern SDL_DECLSPEC void SDLCALL SDL_LogTrace(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  243. /**
  244. * Log a message with SDL_LOG_PRIORITY_VERBOSE.
  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. * \threadsafety It is safe to call this function from any thread.
  252. *
  253. * \since This function is available since SDL 3.1.3.
  254. *
  255. * \sa SDL_Log
  256. * \sa SDL_LogCritical
  257. * \sa SDL_LogDebug
  258. * \sa SDL_LogError
  259. * \sa SDL_LogInfo
  260. * \sa SDL_LogMessage
  261. * \sa SDL_LogMessageV
  262. * \sa SDL_LogWarn
  263. */
  264. extern SDL_DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  265. /**
  266. * Log a message with SDL_LOG_PRIORITY_DEBUG.
  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. * \threadsafety It is safe to call this function from any thread.
  274. *
  275. * \since This function is available since SDL 3.1.3.
  276. *
  277. * \sa SDL_Log
  278. * \sa SDL_LogCritical
  279. * \sa SDL_LogError
  280. * \sa SDL_LogInfo
  281. * \sa SDL_LogMessage
  282. * \sa SDL_LogMessageV
  283. * \sa SDL_LogTrace
  284. * \sa SDL_LogVerbose
  285. * \sa SDL_LogWarn
  286. */
  287. extern SDL_DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  288. /**
  289. * Log a message with SDL_LOG_PRIORITY_INFO.
  290. *
  291. * \param category the category of the message.
  292. * \param fmt a printf() style message format string.
  293. * \param ... additional parameters matching % tokens in the **fmt** string,
  294. * if any.
  295. *
  296. * \threadsafety It is safe to call this function from any thread.
  297. *
  298. * \since This function is available since SDL 3.1.3.
  299. *
  300. * \sa SDL_Log
  301. * \sa SDL_LogCritical
  302. * \sa SDL_LogDebug
  303. * \sa SDL_LogError
  304. * \sa SDL_LogMessage
  305. * \sa SDL_LogMessageV
  306. * \sa SDL_LogTrace
  307. * \sa SDL_LogVerbose
  308. * \sa SDL_LogWarn
  309. */
  310. extern SDL_DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  311. /**
  312. * Log a message with SDL_LOG_PRIORITY_WARN.
  313. *
  314. * \param category the category of the message.
  315. * \param fmt a printf() style message format string.
  316. * \param ... additional parameters matching % tokens in the **fmt** string,
  317. * if any.
  318. *
  319. * \threadsafety It is safe to call this function from any thread.
  320. *
  321. * \since This function is available since SDL 3.1.3.
  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_LogMessageV
  330. * \sa SDL_LogTrace
  331. * \sa SDL_LogVerbose
  332. */
  333. extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  334. /**
  335. * Log a message with SDL_LOG_PRIORITY_ERROR.
  336. *
  337. * \param category the category of the message.
  338. * \param fmt a printf() style message format string.
  339. * \param ... additional parameters matching % tokens in the **fmt** string,
  340. * if any.
  341. *
  342. * \threadsafety It is safe to call this function from any thread.
  343. *
  344. * \since This function is available since SDL 3.1.3.
  345. *
  346. * \sa SDL_Log
  347. * \sa SDL_LogCritical
  348. * \sa SDL_LogDebug
  349. * \sa SDL_LogInfo
  350. * \sa SDL_LogMessage
  351. * \sa SDL_LogMessageV
  352. * \sa SDL_LogTrace
  353. * \sa SDL_LogVerbose
  354. * \sa SDL_LogWarn
  355. */
  356. extern SDL_DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  357. /**
  358. * Log a message with SDL_LOG_PRIORITY_CRITICAL.
  359. *
  360. * \param category the category of the message.
  361. * \param fmt a printf() style message format string.
  362. * \param ... additional parameters matching % tokens in the **fmt** string,
  363. * if any.
  364. *
  365. * \threadsafety It is safe to call this function from any thread.
  366. *
  367. * \since This function is available since SDL 3.1.3.
  368. *
  369. * \sa SDL_Log
  370. * \sa SDL_LogDebug
  371. * \sa SDL_LogError
  372. * \sa SDL_LogInfo
  373. * \sa SDL_LogMessage
  374. * \sa SDL_LogMessageV
  375. * \sa SDL_LogTrace
  376. * \sa SDL_LogVerbose
  377. * \sa SDL_LogWarn
  378. */
  379. extern SDL_DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  380. /**
  381. * Log a message with the specified category and priority.
  382. *
  383. * \param category the category of the message.
  384. * \param priority the priority of the message.
  385. * \param fmt a printf() style message format string.
  386. * \param ... additional parameters matching % tokens in the **fmt** string,
  387. * if any.
  388. *
  389. * \threadsafety It is safe to call this function from any thread.
  390. *
  391. * \since This function is available since SDL 3.1.3.
  392. *
  393. * \sa SDL_Log
  394. * \sa SDL_LogCritical
  395. * \sa SDL_LogDebug
  396. * \sa SDL_LogError
  397. * \sa SDL_LogInfo
  398. * \sa SDL_LogMessageV
  399. * \sa SDL_LogTrace
  400. * \sa SDL_LogVerbose
  401. * \sa SDL_LogWarn
  402. */
  403. extern SDL_DECLSPEC void SDLCALL SDL_LogMessage(int category,
  404. SDL_LogPriority priority,
  405. SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
  406. /**
  407. * Log a message with the specified category and priority.
  408. *
  409. * \param category the category of the message.
  410. * \param priority the priority of the message.
  411. * \param fmt a printf() style message format string.
  412. * \param ap a variable argument list.
  413. *
  414. * \threadsafety It is safe to call this function from any thread.
  415. *
  416. * \since This function is available since SDL 3.1.3.
  417. *
  418. * \sa SDL_Log
  419. * \sa SDL_LogCritical
  420. * \sa SDL_LogDebug
  421. * \sa SDL_LogError
  422. * \sa SDL_LogInfo
  423. * \sa SDL_LogMessage
  424. * \sa SDL_LogTrace
  425. * \sa SDL_LogVerbose
  426. * \sa SDL_LogWarn
  427. */
  428. extern SDL_DECLSPEC void SDLCALL SDL_LogMessageV(int category,
  429. SDL_LogPriority priority,
  430. SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);
  431. /**
  432. * The prototype for the log output callback function.
  433. *
  434. * This function is called by SDL when there is new text to be logged. A mutex
  435. * is held so that this function is never called by more than one thread at
  436. * once.
  437. *
  438. * \param userdata what was passed as `userdata` to
  439. * SDL_SetLogOutputFunction().
  440. * \param category the category of the message.
  441. * \param priority the priority of the message.
  442. * \param message the message being output.
  443. *
  444. * \since This datatype is available since SDL 3.1.3.
  445. */
  446. typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);
  447. /**
  448. * Get the default log output function.
  449. *
  450. * \returns the default log output callback.
  451. *
  452. * \threadsafety It is safe to call this function from any thread.
  453. *
  454. * \since This function is available since SDL 3.2.0.
  455. *
  456. * \sa SDL_SetLogOutputFunction
  457. * \sa SDL_GetLogOutputFunction
  458. */
  459. extern SDL_DECLSPEC SDL_LogOutputFunction SDLCALL SDL_GetDefaultLogOutputFunction(void);
  460. /**
  461. * Get the current log output function.
  462. *
  463. * \param callback an SDL_LogOutputFunction filled in with the current log
  464. * callback.
  465. * \param userdata a pointer filled in with the pointer that is passed to
  466. * `callback`.
  467. *
  468. * \threadsafety It is safe to call this function from any thread.
  469. *
  470. * \since This function is available since SDL 3.1.3.
  471. *
  472. * \sa SDL_GetDefaultLogOutputFunction
  473. * \sa SDL_SetLogOutputFunction
  474. */
  475. extern SDL_DECLSPEC void SDLCALL SDL_GetLogOutputFunction(SDL_LogOutputFunction *callback, void **userdata);
  476. /**
  477. * Replace the default log output function with one of your own.
  478. *
  479. * \param callback an SDL_LogOutputFunction to call instead of the default.
  480. * \param userdata a pointer that is passed to `callback`.
  481. *
  482. * \threadsafety It is safe to call this function from any thread.
  483. *
  484. * \since This function is available since SDL 3.1.3.
  485. *
  486. * \sa SDL_GetDefaultLogOutputFunction
  487. * \sa SDL_GetLogOutputFunction
  488. */
  489. extern SDL_DECLSPEC void SDLCALL SDL_SetLogOutputFunction(SDL_LogOutputFunction callback, void *userdata);
  490. /* Ends C function definitions when using C++ */
  491. #ifdef __cplusplus
  492. }
  493. #endif
  494. #include <SDL3/SDL_close_code.h>
  495. #endif /* SDL_log_h_ */