Simple log messages with priorities and categories.
More...
A message's LogPriority signifies how important the message is. A message's LogCategory signifies from what domain it belongs to. Every category has a minimum priority specified: when a message belongs to that category, it will only be sent out if it has that minimum priority or higher.
SDL's own logs are sent below the default priority threshold, so they are quiet by default.
You can change the log verbosity programmatically using LogCategory.SetLogPriority() or with SDL_SetHint(SDL_HINT_LOGGING, ...), or with the "SDL_LOGGING" environment variable. This variable is a comma separated set of category=level tokens that define the default logging levels for SDL applications.
The category can be a numeric category, one of "app", "error", "assert", "system", "audio", "video", "render", "input", "test", or *
for any unspecified category.
The level can be a numeric level, one of "trace", "verbose", "debug", "info", "warn", "error", "critical", or "quiet" to disable that category.
You can omit the category if you want to set the logging level for all categories.
If this hint isn't set, the default log levels are equivalent to:
app=info,assert=warn,test=verbose,*=error
Here's where the messages go on different platforms:
- Windows: debug output stream
- Android: log output
- Others: standard error output (stderr)
You don't need to have a newline (@n
) on the end of messages, the functions will do that for you. For consistent behavior cross-platform, you shouldn't have any newlines in messages, such as to log multiple lines in one call; unusual platform-specific behavior can be observed in such usage. Do one log call per line instead, with no newlines in messages.
Each log call is atomic, so you won't see log messages cut off one another when logging from multiple threads.
◆ LogOutputCB
This function is called by SDL when there is new text to be logged. A mutex is held so that this function is never called by more than one thread at once.
- Parameters
-
category | the category of the message. |
priority | the priority of the message. |
message | the message being output. |
- Since
- This datatype is available since SDL 3.2.0.
- Category:
- Listener callback
- See also
- LogOutputFunction
◆ LogOutputFunction
This function is called by SDL when there is new text to be logged. A mutex is held so that this function is never called by more than one thread at once.
- Parameters
-
userdata | what was passed as userdata to SetLogOutputFunction(). |
category | the category of the message. |
priority | the priority of the message. |
message | the message being output. |
- Since
- This datatype is available since SDL 3.2.0.
◆ LogPriority
- Since
- This enum is available since SDL 3.2.0.
◆ GetDefaultLogOutputFunction()
◆ GetLogOutputFunction() [1/2]
◆ GetLogOutputFunction() [2/2]
- Parameters
-
callback | an LogOutputFunction filled in with the current log callback. |
userdata | a pointer filled in with the pointer that is passed to callback . |
- Thread safety:
- It is safe to call this function from any thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- GetDefaultLogOutputFunction()
-
SetLogOutputFunction()
◆ Log()
template<class... ARGS>
void SDL::Log |
( |
std::string_view |
fmt, |
|
|
ARGS &&... |
args |
|
) |
| |
|
inline |
◆ LogUnformatted()
◆ ResetLogOutputFunction()
void SDL::ResetLogOutputFunction |
( |
| ) |
|
|
inline |
◆ SetLogOutputFunction() [1/2]
◆ SetLogOutputFunction() [2/2]
◆ SetLogPriorityPrefix()
By default LOG_PRIORITY_INFO and below have no prefix, and LOG_PRIORITY_WARN and higher have a prefix showing their priority, e.g. "WARNING: ".
- Parameters
-
priority | the LogPriority to modify. |
prefix | the prefix to use for that log priority, or nullptr to use no prefix. |
- Exceptions
-
- Thread safety:
- It is safe to call this function from any thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- LogCategory.SetLogPriorities
-
LogCategory.SetLogPriority
◆ LOG_CATEGORY_APPLICATION
Initial value:=
SDL_LOG_CATEGORY_APPLICATION
◆ LOG_CATEGORY_RESERVED10
Initial value:=
SDL_LOG_CATEGORY_RESERVED10
◆ LOG_CATEGORY_RESERVED2
Initial value:=
SDL_LOG_CATEGORY_RESERVED2
◆ LOG_CATEGORY_RESERVED3
Initial value:=
SDL_LOG_CATEGORY_RESERVED3
◆ LOG_CATEGORY_RESERVED4
Initial value:=
SDL_LOG_CATEGORY_RESERVED4
◆ LOG_CATEGORY_RESERVED5
Initial value:=
SDL_LOG_CATEGORY_RESERVED5
◆ LOG_CATEGORY_RESERVED6
Initial value:=
SDL_LOG_CATEGORY_RESERVED6
◆ LOG_CATEGORY_RESERVED7
Initial value:=
SDL_LOG_CATEGORY_RESERVED7
◆ LOG_CATEGORY_RESERVED8
Initial value:=
SDL_LOG_CATEGORY_RESERVED8
◆ LOG_CATEGORY_RESERVED9
Initial value:=
SDL_LOG_CATEGORY_RESERVED9
◆ LOG_PRIORITY_CRITICAL
Initial value:=
SDL_LOG_PRIORITY_CRITICAL
◆ LOG_PRIORITY_INVALID
Initial value:=
SDL_LOG_PRIORITY_INVALID
◆ LOG_PRIORITY_VERBOSE
Initial value:=
SDL_LOG_PRIORITY_VERBOSE