Path: blob/master/thirdparty/sdl/include/SDL3/SDL_log.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* # CategoryLog23*24* Simple log messages with priorities and categories. A message's25* SDL_LogPriority signifies how important the message is. A message's26* SDL_LogCategory signifies from what domain it belongs to. Every category27* has a minimum priority specified: when a message belongs to that category,28* it will only be sent out if it has that minimum priority or higher.29*30* SDL's own logs are sent below the default priority threshold, so they are31* quiet by default.32*33* You can change the log verbosity programmatically using34* SDL_SetLogPriority() or with SDL_SetHint(SDL_HINT_LOGGING, ...), or with35* the "SDL_LOGGING" environment variable. This variable is a comma separated36* set of category=level tokens that define the default logging levels for SDL37* applications.38*39* The category can be a numeric category, one of "app", "error", "assert",40* "system", "audio", "video", "render", "input", "test", or `*` for any41* unspecified category.42*43* The level can be a numeric level, one of "trace", "verbose", "debug",44* "info", "warn", "error", "critical", or "quiet" to disable that category.45*46* You can omit the category if you want to set the logging level for all47* categories.48*49* If this hint isn't set, the default log levels are equivalent to:50*51* `app=info,assert=warn,test=verbose,*=error`52*53* Here's where the messages go on different platforms:54*55* - Windows: debug output stream56* - Android: log output57* - Others: standard error output (stderr)58*59* You don't need to have a newline (`\n`) on the end of messages, the60* functions will do that for you. For consistent behavior cross-platform, you61* shouldn't have any newlines in messages, such as to log multiple lines in62* one call; unusual platform-specific behavior can be observed in such usage.63* Do one log call per line instead, with no newlines in messages.64*65* Each log call is atomic, so you won't see log messages cut off one another66* when logging from multiple threads.67*/6869#ifndef SDL_log_h_70#define SDL_log_h_7172#include <SDL3/SDL_stdinc.h>7374#include <SDL3/SDL_begin_code.h>75/* Set up for C function definitions, even when using C++ */76#ifdef __cplusplus77extern "C" {78#endif7980/**81* The predefined log categories82*83* By default the application and gpu categories are enabled at the INFO84* level, the assert category is enabled at the WARN level, test is enabled at85* the VERBOSE level and all other categories are enabled at the ERROR level.86*87* \since This enum is available since SDL 3.2.0.88*/89typedef enum SDL_LogCategory90{91SDL_LOG_CATEGORY_APPLICATION,92SDL_LOG_CATEGORY_ERROR,93SDL_LOG_CATEGORY_ASSERT,94SDL_LOG_CATEGORY_SYSTEM,95SDL_LOG_CATEGORY_AUDIO,96SDL_LOG_CATEGORY_VIDEO,97SDL_LOG_CATEGORY_RENDER,98SDL_LOG_CATEGORY_INPUT,99SDL_LOG_CATEGORY_TEST,100SDL_LOG_CATEGORY_GPU,101102/* Reserved for future SDL library use */103SDL_LOG_CATEGORY_RESERVED2,104SDL_LOG_CATEGORY_RESERVED3,105SDL_LOG_CATEGORY_RESERVED4,106SDL_LOG_CATEGORY_RESERVED5,107SDL_LOG_CATEGORY_RESERVED6,108SDL_LOG_CATEGORY_RESERVED7,109SDL_LOG_CATEGORY_RESERVED8,110SDL_LOG_CATEGORY_RESERVED9,111SDL_LOG_CATEGORY_RESERVED10,112113/* Beyond this point is reserved for application use, e.g.114enum {115MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,116MYAPP_CATEGORY_AWESOME2,117MYAPP_CATEGORY_AWESOME3,118...119};120*/121SDL_LOG_CATEGORY_CUSTOM122} SDL_LogCategory;123124/**125* The predefined log priorities126*127* \since This enum is available since SDL 3.2.0.128*/129typedef enum SDL_LogPriority130{131SDL_LOG_PRIORITY_INVALID,132SDL_LOG_PRIORITY_TRACE,133SDL_LOG_PRIORITY_VERBOSE,134SDL_LOG_PRIORITY_DEBUG,135SDL_LOG_PRIORITY_INFO,136SDL_LOG_PRIORITY_WARN,137SDL_LOG_PRIORITY_ERROR,138SDL_LOG_PRIORITY_CRITICAL,139SDL_LOG_PRIORITY_COUNT140} SDL_LogPriority;141142143/**144* Set the priority of all log categories.145*146* \param priority the SDL_LogPriority to assign.147*148* \threadsafety It is safe to call this function from any thread.149*150* \since This function is available since SDL 3.2.0.151*152* \sa SDL_ResetLogPriorities153* \sa SDL_SetLogPriority154*/155extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriorities(SDL_LogPriority priority);156157/**158* Set the priority of a particular log category.159*160* \param category the category to assign a priority to.161* \param priority the SDL_LogPriority to assign.162*163* \threadsafety It is safe to call this function from any thread.164*165* \since This function is available since SDL 3.2.0.166*167* \sa SDL_GetLogPriority168* \sa SDL_ResetLogPriorities169* \sa SDL_SetLogPriorities170*/171extern SDL_DECLSPEC void SDLCALL SDL_SetLogPriority(int category, SDL_LogPriority priority);172173/**174* Get the priority of a particular log category.175*176* \param category the category to query.177* \returns the SDL_LogPriority for the requested category.178*179* \threadsafety It is safe to call this function from any thread.180*181* \since This function is available since SDL 3.2.0.182*183* \sa SDL_SetLogPriority184*/185extern SDL_DECLSPEC SDL_LogPriority SDLCALL SDL_GetLogPriority(int category);186187/**188* Reset all priorities to default.189*190* This is called by SDL_Quit().191*192* \threadsafety It is safe to call this function from any thread.193*194* \since This function is available since SDL 3.2.0.195*196* \sa SDL_SetLogPriorities197* \sa SDL_SetLogPriority198*/199extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void);200201/**202* Set the text prepended to log messages of a given priority.203*204* By default SDL_LOG_PRIORITY_INFO and below have no prefix, and205* SDL_LOG_PRIORITY_WARN and higher have a prefix showing their priority, e.g.206* "WARNING: ".207*208* \param priority the SDL_LogPriority to modify.209* \param prefix the prefix to use for that log priority, or NULL to use no210* prefix.211* \returns true on success or false on failure; call SDL_GetError() for more212* information.213*214* \threadsafety It is safe to call this function from any thread.215*216* \since This function is available since SDL 3.2.0.217*218* \sa SDL_SetLogPriorities219* \sa SDL_SetLogPriority220*/221extern SDL_DECLSPEC bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix);222223/**224* Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.225*226* \param fmt a printf() style message format string.227* \param ... additional parameters matching % tokens in the `fmt` string, if228* any.229*230* \threadsafety It is safe to call this function from any thread.231*232* \since This function is available since SDL 3.2.0.233*234* \sa SDL_LogCritical235* \sa SDL_LogDebug236* \sa SDL_LogError237* \sa SDL_LogInfo238* \sa SDL_LogMessage239* \sa SDL_LogMessageV240* \sa SDL_LogTrace241* \sa SDL_LogVerbose242* \sa SDL_LogWarn243*/244extern SDL_DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);245246/**247* Log a message with SDL_LOG_PRIORITY_TRACE.248*249* \param category the category of the message.250* \param fmt a printf() style message format string.251* \param ... additional parameters matching % tokens in the **fmt** string,252* if any.253*254* \threadsafety It is safe to call this function from any thread.255*256* \since This function is available since SDL 3.2.0.257*258* \sa SDL_Log259* \sa SDL_LogCritical260* \sa SDL_LogDebug261* \sa SDL_LogError262* \sa SDL_LogInfo263* \sa SDL_LogMessage264* \sa SDL_LogMessageV265* \sa SDL_LogTrace266* \sa SDL_LogVerbose267* \sa SDL_LogWarn268*/269extern SDL_DECLSPEC void SDLCALL SDL_LogTrace(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);270271/**272* Log a message with SDL_LOG_PRIORITY_VERBOSE.273*274* \param category the category of the message.275* \param fmt a printf() style message format string.276* \param ... additional parameters matching % tokens in the **fmt** string,277* if any.278*279* \threadsafety It is safe to call this function from any thread.280*281* \since This function is available since SDL 3.2.0.282*283* \sa SDL_Log284* \sa SDL_LogCritical285* \sa SDL_LogDebug286* \sa SDL_LogError287* \sa SDL_LogInfo288* \sa SDL_LogMessage289* \sa SDL_LogMessageV290* \sa SDL_LogWarn291*/292extern SDL_DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);293294/**295* Log a message with SDL_LOG_PRIORITY_DEBUG.296*297* \param category the category of the message.298* \param fmt a printf() style message format string.299* \param ... additional parameters matching % tokens in the **fmt** string,300* if any.301*302* \threadsafety It is safe to call this function from any thread.303*304* \since This function is available since SDL 3.2.0.305*306* \sa SDL_Log307* \sa SDL_LogCritical308* \sa SDL_LogError309* \sa SDL_LogInfo310* \sa SDL_LogMessage311* \sa SDL_LogMessageV312* \sa SDL_LogTrace313* \sa SDL_LogVerbose314* \sa SDL_LogWarn315*/316extern SDL_DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);317318/**319* Log a message with SDL_LOG_PRIORITY_INFO.320*321* \param category the category of the message.322* \param fmt a printf() style message format string.323* \param ... additional parameters matching % tokens in the **fmt** string,324* if any.325*326* \threadsafety It is safe to call this function from any thread.327*328* \since This function is available since SDL 3.2.0.329*330* \sa SDL_Log331* \sa SDL_LogCritical332* \sa SDL_LogDebug333* \sa SDL_LogError334* \sa SDL_LogMessage335* \sa SDL_LogMessageV336* \sa SDL_LogTrace337* \sa SDL_LogVerbose338* \sa SDL_LogWarn339*/340extern SDL_DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);341342/**343* Log a message with SDL_LOG_PRIORITY_WARN.344*345* \param category the category of the message.346* \param fmt a printf() style message format string.347* \param ... additional parameters matching % tokens in the **fmt** string,348* if any.349*350* \threadsafety It is safe to call this function from any thread.351*352* \since This function is available since SDL 3.2.0.353*354* \sa SDL_Log355* \sa SDL_LogCritical356* \sa SDL_LogDebug357* \sa SDL_LogError358* \sa SDL_LogInfo359* \sa SDL_LogMessage360* \sa SDL_LogMessageV361* \sa SDL_LogTrace362* \sa SDL_LogVerbose363*/364extern SDL_DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);365366/**367* Log a message with SDL_LOG_PRIORITY_ERROR.368*369* \param category the category of the message.370* \param fmt a printf() style message format string.371* \param ... additional parameters matching % tokens in the **fmt** string,372* if any.373*374* \threadsafety It is safe to call this function from any thread.375*376* \since This function is available since SDL 3.2.0.377*378* \sa SDL_Log379* \sa SDL_LogCritical380* \sa SDL_LogDebug381* \sa SDL_LogInfo382* \sa SDL_LogMessage383* \sa SDL_LogMessageV384* \sa SDL_LogTrace385* \sa SDL_LogVerbose386* \sa SDL_LogWarn387*/388extern SDL_DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);389390/**391* Log a message with SDL_LOG_PRIORITY_CRITICAL.392*393* \param category the category of the message.394* \param fmt a printf() style message format string.395* \param ... additional parameters matching % tokens in the **fmt** string,396* if any.397*398* \threadsafety It is safe to call this function from any thread.399*400* \since This function is available since SDL 3.2.0.401*402* \sa SDL_Log403* \sa SDL_LogDebug404* \sa SDL_LogError405* \sa SDL_LogInfo406* \sa SDL_LogMessage407* \sa SDL_LogMessageV408* \sa SDL_LogTrace409* \sa SDL_LogVerbose410* \sa SDL_LogWarn411*/412extern SDL_DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);413414/**415* Log a message with the specified category and priority.416*417* \param category the category of the message.418* \param priority the priority of the message.419* \param fmt a printf() style message format string.420* \param ... additional parameters matching % tokens in the **fmt** string,421* if any.422*423* \threadsafety It is safe to call this function from any thread.424*425* \since This function is available since SDL 3.2.0.426*427* \sa SDL_Log428* \sa SDL_LogCritical429* \sa SDL_LogDebug430* \sa SDL_LogError431* \sa SDL_LogInfo432* \sa SDL_LogMessageV433* \sa SDL_LogTrace434* \sa SDL_LogVerbose435* \sa SDL_LogWarn436*/437extern SDL_DECLSPEC void SDLCALL SDL_LogMessage(int category,438SDL_LogPriority priority,439SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);440441/**442* Log a message with the specified category and priority.443*444* \param category the category of the message.445* \param priority the priority of the message.446* \param fmt a printf() style message format string.447* \param ap a variable argument list.448*449* \threadsafety It is safe to call this function from any thread.450*451* \since This function is available since SDL 3.2.0.452*453* \sa SDL_Log454* \sa SDL_LogCritical455* \sa SDL_LogDebug456* \sa SDL_LogError457* \sa SDL_LogInfo458* \sa SDL_LogMessage459* \sa SDL_LogTrace460* \sa SDL_LogVerbose461* \sa SDL_LogWarn462*/463extern SDL_DECLSPEC void SDLCALL SDL_LogMessageV(int category,464SDL_LogPriority priority,465SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);466467/**468* The prototype for the log output callback function.469*470* This function is called by SDL when there is new text to be logged. A mutex471* is held so that this function is never called by more than one thread at472* once.473*474* \param userdata what was passed as `userdata` to475* SDL_SetLogOutputFunction().476* \param category the category of the message.477* \param priority the priority of the message.478* \param message the message being output.479*480* \since This datatype is available since SDL 3.2.0.481*/482typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);483484/**485* Get the default log output function.486*487* \returns the default log output callback.488*489* \threadsafety It is safe to call this function from any thread.490*491* \since This function is available since SDL 3.2.0.492*493* \sa SDL_SetLogOutputFunction494* \sa SDL_GetLogOutputFunction495*/496extern SDL_DECLSPEC SDL_LogOutputFunction SDLCALL SDL_GetDefaultLogOutputFunction(void);497498/**499* Get the current log output function.500*501* \param callback an SDL_LogOutputFunction filled in with the current log502* callback.503* \param userdata a pointer filled in with the pointer that is passed to504* `callback`.505*506* \threadsafety It is safe to call this function from any thread.507*508* \since This function is available since SDL 3.2.0.509*510* \sa SDL_GetDefaultLogOutputFunction511* \sa SDL_SetLogOutputFunction512*/513extern SDL_DECLSPEC void SDLCALL SDL_GetLogOutputFunction(SDL_LogOutputFunction *callback, void **userdata);514515/**516* Replace the default log output function with one of your own.517*518* \param callback an SDL_LogOutputFunction to call instead of the default.519* \param userdata a pointer that is passed to `callback`.520*521* \threadsafety It is safe to call this function from any thread.522*523* \since This function is available since SDL 3.2.0.524*525* \sa SDL_GetDefaultLogOutputFunction526* \sa SDL_GetLogOutputFunction527*/528extern SDL_DECLSPEC void SDLCALL SDL_SetLogOutputFunction(SDL_LogOutputFunction callback, void *userdata);529530531/* Ends C function definitions when using C++ */532#ifdef __cplusplus533}534#endif535#include <SDL3/SDL_close_code.h>536537#endif /* SDL_log_h_ */538539540