SDL_log.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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. * # 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 "trace", "verbose", "debug",
  41. * "info", "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. * You don't need to have a newline (`\n`) on the end of messages, the
  57. * functions will do that for you. For consistent behavior cross-platform, you
  58. * shouldn't have any newlines in messages, such as to log multiple lines in
  59. * one call; unusual platform-specific behavior can be observed in such usage.
  60. * Do one log call per line instead, with no newlines in messages.
  61. *
  62. * Each log call is atomic, so you won't see log messages cut off one another
  63. * when logging from multiple threads.
  64. */
  65. #ifndef SDL_log_h_
  66. #define SDL_log_h_
  67. #include <SDL3/SDL_stdinc.h>
  68. #include <SDL3/SDL_begin_code.h>
  69. /* Set up for C function definitions, even when using C++ */
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73. /**
  74. * The predefined log categories
  75. *
  76. * By default the application and gpu categories are enabled at the INFO
  77. * level, the assert category is enabled at the WARN level, test is enabled at
  78. * the VERBOSE level and all other categories are enabled at the ERROR level.
  79. *
  80. * \since This enum is available since SDL 3.2.0.
  81. */
  82. typedef enum SDL_LogCategory
  83. {
  84. SDL_LOG_CATEGORY_APPLICATION,
  85. SDL_LOG_CATEGORY_ERROR,
  86. SDL_LOG_CATEGORY_ASSERT,
  87. SDL_LOG_CATEGORY_SYSTEM,
  88. SDL_LOG_CATEGORY_AUDIO,
  89. SDL_LOG_CATEGORY_VIDEO,
  90. SDL_LOG_CATEGORY_RENDER,
  91. SDL_LOG_CATEGORY_INPUT,
  92. SDL_LOG_CATEGORY_TEST,
  93. SDL_LOG_CATEGORY_GPU,
  94. /* Reserved for future SDL library use */
  95. SDL_LOG_CATEGORY_RESERVED2,
  96. SDL_LOG_CATEGORY_RESERVED3,
  97. SDL_LOG_CATEGORY_RESERVED4,
  98. SDL_LOG_CATEGORY_RESERVED5,
  99. SDL_LOG_CATEGORY_RESERVED6,
  100. SDL_LOG_CATEGORY_RESERVED7,
  101. SDL_LOG_CATEGORY_RESERVED8,
  102. SDL_LOG_CATEGORY_RESERVED9,
  103. SDL_LOG_CATEGORY_RESERVED10,
  104. /* Beyond this point is reserved for application use, e.g.
  105. enum {
  106. MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,
  107. MYAPP_CATEGORY_AWESOME2,
  108. MYAPP_CATEGORY_AWESOME3,
  109. ...
  110. };
  111. */
  112. SDL_LOG_CATEGORY_CUSTOM
  113. } SDL_LogCategory;
  114. /**
  115. * The predefined log priorities
  116. *
  117. * \since This enum is available since SDL 3.2.0.
  118. */
  119. typedef enum SDL_LogPriority
  120. {
  121. SDL_LOG_PRIORITY_INVALID,
  122. SDL_LOG_PRIORITY_TRACE,
  123. SDL_LOG_PRIORITY_VERBOSE,
  124. SDL_LOG_PRIORITY_DEBUG,
  125. SDL_LOG_PRIORITY_INFO,
  126. SDL_LOG_PRIORITY_WARN,
  127. SDL_LOG_PRIORITY_ERROR,
  128. SDL_LOG_PRIORITY_CRITICAL,
  129. SDL_LOG_PRIORITY_COUNT
  130. } SDL_LogPriority;
  131. /**
  132. * Set the priority of all log categories.
  133. *
  134. * \param priority the SDL_LogPriority to assign.
  135. *
  136. * \threadsafety It is safe to call this function from any thread.
  137. *
  138. * \since This function is available since SDL 3.2.0.
  139. *
  140. * \sa SDL_ResetLogPriorities
  141. * \sa SDL_SetLogPriority
  142. */
  143. extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriorities(SDL_LogPriority priority);
  144. /**
  145. * Set the priority of a particular log category.
  146. *
  147. * \param category the category to assign a priority to.
  148. * \param priority the SDL_LogPriority to assign.
  149. *
  150. * \threadsafety It is safe to call this function from any thread.
  151. *
  152. * \since This function is available since SDL 3.2.0.
  153. *
  154. * \sa SDL_GetLogPriority
  155. * \sa SDL_ResetLogPriorities
  156. * \sa SDL_SetLogPriorities
  157. */
  158. extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category, SDL_LogPriority priority);
  159. /**
  160. * Get the priority of a particular log category.
  161. *
  162. * \param category the category to query.
  163. * \returns the SDL_LogPriority for the requested category.
  164. *
  165. * \threadsafety It is safe to call this function from any thread.
  166. *
  167. * \since This function is available since SDL 3.2.0.
  168. *
  169. * \sa SDL_SetLogPriority
  170. */
  171. extern SDL_DECLSPEC SDL_LogPriority SDLCALL SDL_GetLogPriority(int category);
  172. /**
  173. * Reset all priorities to default.
  174. *
  175. * This is called by SDL_Quit().
  176. *
  177. * \threadsafety It is safe to call this function from any thread.
  178. *
  179. * \since This function is available since SDL 3.2.0.
  180. *
  181. * \sa SDL_SetLogPriorities
  182. * \sa SDL_SetLogPriority
  183. */
  184. extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void);
  185. /**
  186. * Set the text prepended to log messages of a given priority.
  187. *
  188. * By default SDL_LOG_PRIORITY_INFO and below have no prefix, and
  189. * SDL_LOG_PRIORITY_WARN and higher have a prefix showing their priority, e.g.
  190. * "WARNING: ".
  191. *
  192. * This function makes a copy of its string argument, **prefix**, so it is not
  193. * necessary to keep the value of **prefix** alive after the call returns.
  194. *
  195. * \param priority the SDL_LogPriority to modify.
  196. * \param prefix the prefix to use for that log priority, or NULL to use no
  197. * prefix.
  198. * \returns true on success or false on failure; call SDL_GetError() for more
  199. * information.
  200. *
  201. * \threadsafety It is safe to call this function from any thread.
  202. *
  203. * \since This function is available since SDL 3.2.0.
  204. *
  205. * \sa SDL_SetLogPriorities
  206. * \sa SDL_SetLogPriority
  207. */
  208. extern SDL_DECLSPEC bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix);
  209. /**
  210. * Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.
  211. *
  212. * \param fmt a printf() style message format string.
  213. * \param ... additional parameters matching % tokens in the `fmt` string, if
  214. * any.
  215. *
  216. * \threadsafety It is safe to call this function from any thread.
  217. *
  218. * \since This function is available since SDL 3.2.0.
  219. *
  220. * \sa SDL_LogCritical
  221. * \sa SDL_LogDebug
  222. * \sa SDL_LogError
  223. * \sa SDL_LogInfo
  224. * \sa SDL_LogMessage
  225. * \sa SDL_LogMessageV
  226. * \sa SDL_LogTrace
  227. * \sa SDL_LogVerbose
  228. * \sa SDL_LogWarn
  229. */
  230. extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
  231. /**
  232. * Log a message with SDL_LOG_PRIORITY_TRACE.
  233. *
  234. * \param category the category of the message.
  235. * \param fmt a printf() style message format string.
  236. * \param ... additional parameters matching % tokens in the **fmt** string,
  237. * if any.
  238. *
  239. * \threadsafety It is safe to call this function from any thread.
  240. *
  241. * \since This function is available since SDL 3.2.0.
  242. *
  243. * \sa SDL_Log
  244. * \sa SDL_LogCritical
  245. * \sa SDL_LogDebug
  246. * \sa SDL_LogError
  247. * \sa SDL_LogInfo
  248. * \sa SDL_LogMessage
  249. * \sa SDL_LogMessageV
  250. * \sa SDL_LogTrace
  251. * \sa SDL_LogVerbose
  252. * \sa SDL_LogWarn
  253. */
  254. extern SDL_DECLSPEC void SDLCALL SDL_LogTrace(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  255. /**
  256. * Log a message with SDL_LOG_PRIORITY_VERBOSE.
  257. *
  258. * \param category the category of the message.
  259. * \param fmt a printf() style message format string.
  260. * \param ... additional parameters matching % tokens in the **fmt** string,
  261. * if any.
  262. *
  263. * \threadsafety It is safe to call this function from any thread.
  264. *
  265. * \since This function is available since SDL 3.2.0.
  266. *
  267. * \sa SDL_Log
  268. * \sa SDL_LogCritical
  269. * \sa SDL_LogDebug
  270. * \sa SDL_LogError
  271. * \sa SDL_LogInfo
  272. * \sa SDL_LogMessage
  273. * \sa SDL_LogMessageV
  274. * \sa SDL_LogWarn
  275. */
  276. extern SDL_DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  277. /**
  278. * Log a message with SDL_LOG_PRIORITY_DEBUG.
  279. *
  280. * \param category the category of the message.
  281. * \param fmt a printf() style message format string.
  282. * \param ... additional parameters matching % tokens in the **fmt** string,
  283. * if any.
  284. *
  285. * \threadsafety It is safe to call this function from any thread.
  286. *
  287. * \since This function is available since SDL 3.2.0.
  288. *
  289. * \sa SDL_Log
  290. * \sa SDL_LogCritical
  291. * \sa SDL_LogError
  292. * \sa SDL_LogInfo
  293. * \sa SDL_LogMessage
  294. * \sa SDL_LogMessageV
  295. * \sa SDL_LogTrace
  296. * \sa SDL_LogVerbose
  297. * \sa SDL_LogWarn
  298. */
  299. extern SDL_DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  300. /**
  301. * Log a message with SDL_LOG_PRIORITY_INFO.
  302. *
  303. * \param category the category of the message.
  304. * \param fmt a printf() style message format string.
  305. * \param ... additional parameters matching % tokens in the **fmt** string,
  306. * if any.
  307. *
  308. * \threadsafety It is safe to call this function from any thread.
  309. *
  310. * \since This function is available since SDL 3.2.0.
  311. *
  312. * \sa SDL_Log
  313. * \sa SDL_LogCritical
  314. * \sa SDL_LogDebug
  315. * \sa SDL_LogError
  316. * \sa SDL_LogMessage
  317. * \sa SDL_LogMessageV
  318. * \sa SDL_LogTrace
  319. * \sa SDL_LogVerbose
  320. * \sa SDL_LogWarn
  321. */
  322. extern SDL_DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  323. /**
  324. * Log a message with SDL_LOG_PRIORITY_WARN.
  325. *
  326. * \param category the category of the message.
  327. * \param fmt a printf() style message format string.
  328. * \param ... additional parameters matching % tokens in the **fmt** string,
  329. * if any.
  330. *
  331. * \threadsafety It is safe to call this function from any thread.
  332. *
  333. * \since This function is available since SDL 3.2.0.
  334. *
  335. * \sa SDL_Log
  336. * \sa SDL_LogCritical
  337. * \sa SDL_LogDebug
  338. * \sa SDL_LogError
  339. * \sa SDL_LogInfo
  340. * \sa SDL_LogMessage
  341. * \sa SDL_LogMessageV
  342. * \sa SDL_LogTrace
  343. * \sa SDL_LogVerbose
  344. */
  345. extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  346. /**
  347. * Log a message with SDL_LOG_PRIORITY_ERROR.
  348. *
  349. * \param category the category of the message.
  350. * \param fmt a printf() style message format string.
  351. * \param ... additional parameters matching % tokens in the **fmt** string,
  352. * if any.
  353. *
  354. * \threadsafety It is safe to call this function from any thread.
  355. *
  356. * \since This function is available since SDL 3.2.0.
  357. *
  358. * \sa SDL_Log
  359. * \sa SDL_LogCritical
  360. * \sa SDL_LogDebug
  361. * \sa SDL_LogInfo
  362. * \sa SDL_LogMessage
  363. * \sa SDL_LogMessageV
  364. * \sa SDL_LogTrace
  365. * \sa SDL_LogVerbose
  366. * \sa SDL_LogWarn
  367. */
  368. extern SDL_DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  369. /**
  370. * Log a message with SDL_LOG_PRIORITY_CRITICAL.
  371. *
  372. * \param category the category of the message.
  373. * \param fmt a printf() style message format string.
  374. * \param ... additional parameters matching % tokens in the **fmt** string,
  375. * if any.
  376. *
  377. * \threadsafety It is safe to call this function from any thread.
  378. *
  379. * \since This function is available since SDL 3.2.0.
  380. *
  381. * \sa SDL_Log
  382. * \sa SDL_LogDebug
  383. * \sa SDL_LogError
  384. * \sa SDL_LogInfo
  385. * \sa SDL_LogMessage
  386. * \sa SDL_LogMessageV
  387. * \sa SDL_LogTrace
  388. * \sa SDL_LogVerbose
  389. * \sa SDL_LogWarn
  390. */
  391. extern SDL_DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  392. /**
  393. * Log a message with the specified category and priority.
  394. *
  395. * \param category the category of the message.
  396. * \param priority the priority of the message.
  397. * \param fmt a printf() style message format string.
  398. * \param ... additional parameters matching % tokens in the **fmt** string,
  399. * if any.
  400. *
  401. * \threadsafety It is safe to call this function from any thread.
  402. *
  403. * \since This function is available since SDL 3.2.0.
  404. *
  405. * \sa SDL_Log
  406. * \sa SDL_LogCritical
  407. * \sa SDL_LogDebug
  408. * \sa SDL_LogError
  409. * \sa SDL_LogInfo
  410. * \sa SDL_LogMessageV
  411. * \sa SDL_LogTrace
  412. * \sa SDL_LogVerbose
  413. * \sa SDL_LogWarn
  414. */
  415. extern SDL_DECLSPEC void SDLCALL SDL_LogMessage(int category,
  416. SDL_LogPriority priority,
  417. SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
  418. /**
  419. * Log a message with the specified category and priority.
  420. *
  421. * \param category the category of the message.
  422. * \param priority the priority of the message.
  423. * \param fmt a printf() style message format string.
  424. * \param ap a variable argument list.
  425. *
  426. * \threadsafety It is safe to call this function from any thread.
  427. *
  428. * \since This function is available since SDL 3.2.0.
  429. *
  430. * \sa SDL_Log
  431. * \sa SDL_LogCritical
  432. * \sa SDL_LogDebug
  433. * \sa SDL_LogError
  434. * \sa SDL_LogInfo
  435. * \sa SDL_LogMessage
  436. * \sa SDL_LogTrace
  437. * \sa SDL_LogVerbose
  438. * \sa SDL_LogWarn
  439. */
  440. extern SDL_DECLSPEC void SDLCALL SDL_LogMessageV(int category,
  441. SDL_LogPriority priority,
  442. SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);
  443. /**
  444. * The prototype for the log output callback function.
  445. *
  446. * This function is called by SDL when there is new text to be logged. A mutex
  447. * is held so that this function is never called by more than one thread at
  448. * once.
  449. *
  450. * \param userdata what was passed as `userdata` to
  451. * SDL_SetLogOutputFunction().
  452. * \param category the category of the message.
  453. * \param priority the priority of the message.
  454. * \param message the message being output.
  455. *
  456. * \since This datatype is available since SDL 3.2.0.
  457. */
  458. typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);
  459. /**
  460. * Get the default log output function.
  461. *
  462. * \returns the default log output callback.
  463. *
  464. * \threadsafety It is safe to call this function from any thread.
  465. *
  466. * \since This function is available since SDL 3.2.0.
  467. *
  468. * \sa SDL_SetLogOutputFunction
  469. * \sa SDL_GetLogOutputFunction
  470. */
  471. extern SDL_DECLSPEC SDL_LogOutputFunction SDLCALL SDL_GetDefaultLogOutputFunction(void);
  472. /**
  473. * Get the current log output function.
  474. *
  475. * \param callback an SDL_LogOutputFunction filled in with the current log
  476. * callback.
  477. * \param userdata a pointer filled in with the pointer that is passed to
  478. * `callback`.
  479. *
  480. * \threadsafety It is safe to call this function from any thread.
  481. *
  482. * \since This function is available since SDL 3.2.0.
  483. *
  484. * \sa SDL_GetDefaultLogOutputFunction
  485. * \sa SDL_SetLogOutputFunction
  486. */
  487. extern SDL_DECLSPEC void SDLCALL SDL_GetLogOutputFunction(SDL_LogOutputFunction *callback, void **userdata);
  488. /**
  489. * Replace the default log output function with one of your own.
  490. *
  491. * \param callback an SDL_LogOutputFunction to call instead of the default.
  492. * \param userdata a pointer that is passed to `callback`.
  493. *
  494. * \threadsafety It is safe to call this function from any thread.
  495. *
  496. * \since This function is available since SDL 3.2.0.
  497. *
  498. * \sa SDL_GetDefaultLogOutputFunction
  499. * \sa SDL_GetLogOutputFunction
  500. */
  501. extern SDL_DECLSPEC void SDLCALL SDL_SetLogOutputFunction(SDL_LogOutputFunction callback, void *userdata);
  502. /* Ends C function definitions when using C++ */
  503. #ifdef __cplusplus
  504. }
  505. #endif
  506. #include <SDL3/SDL_close_code.h>
  507. #endif /* SDL_log_h_ */