[SDL2] Redirect log messages into our system.
This commit is contained in:
parent
11d79c6c1c
commit
05a62673f7
|
@ -31,6 +31,7 @@ SDLAudioDriver::~SDLAudioDriver() {
|
|||
};
|
||||
|
||||
bool SDLAudioDriver::Initialize() {
|
||||
XELOG_SDL_INIT()
|
||||
SDL_version ver = {};
|
||||
SDL_GetVersion(&ver);
|
||||
if ((ver.major < 2) || (ver.major == 2 && ver.minor == 0 && ver.patch < 8)) {
|
||||
|
|
|
@ -49,7 +49,7 @@ void AppendLogLine(LogLevel log_level, const char prefix_char, size_t written);
|
|||
|
||||
} // namespace internal
|
||||
|
||||
// Appends a line to the log with printf-style formatting.
|
||||
// Appends a line to the log with {fmt}-style formatting.
|
||||
template <typename... Args>
|
||||
void AppendLogLineFormat(LogLevel log_level, const char prefix_char,
|
||||
const char* format, const Args&... args) {
|
||||
|
@ -119,6 +119,40 @@ void XELOGFS(const char* format, const Args&... args) {
|
|||
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'F', format, args...);
|
||||
}
|
||||
|
||||
// Redirect SDL_Log* output (internal library stuff) to our log system.
|
||||
// Can't execute this code here without linking SDL2 into all projects.
|
||||
// Use this macro everywhere SDL_InitSubSystem() is called.
|
||||
#define XELOG_SDL_INIT() \
|
||||
{ \
|
||||
SDL_LogSetOutputFunction( \
|
||||
[](void* userdata, int category, SDL_LogPriority priority, \
|
||||
const char* message) { \
|
||||
const char* msg_fmt = "SDL: {}"; \
|
||||
switch (priority) { \
|
||||
case SDL_LOG_PRIORITY_VERBOSE: \
|
||||
case SDL_LOG_PRIORITY_DEBUG: \
|
||||
XELOGD(msg_fmt, message); \
|
||||
break; \
|
||||
case SDL_LOG_PRIORITY_INFO: \
|
||||
XELOGI(msg_fmt, message); \
|
||||
break; \
|
||||
case SDL_LOG_PRIORITY_WARN: \
|
||||
XELOGW(msg_fmt, message); \
|
||||
break; \
|
||||
case SDL_LOG_PRIORITY_ERROR: \
|
||||
case SDL_LOG_PRIORITY_CRITICAL: \
|
||||
XELOGE(msg_fmt, message); \
|
||||
break; \
|
||||
default: \
|
||||
XELOGI(msg_fmt, message); \
|
||||
assert_always("SDL: Unknown log priority"); \
|
||||
break; \
|
||||
} \
|
||||
}, \
|
||||
nullptr); \
|
||||
SDL_LogSetAllPriority(SDL_LogPriority::SDL_LOG_PRIORITY_VERBOSE); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define XELOGDUMMY \
|
||||
|
@ -135,6 +169,8 @@ void XELOGFS(const char* format, const Args&... args) {
|
|||
#define XELOGKERNEL(...) XELOGDUMMY
|
||||
#define XELOGFS(...) XELOGDUMMY
|
||||
|
||||
#define XELOG_SDL_INIT() XELOGDUMMY
|
||||
|
||||
#undef XELOGDUMMY
|
||||
|
||||
#endif // ENABLE_LOGGING
|
||||
|
|
|
@ -6,7 +6,7 @@ project("xenia-base")
|
|||
kind("StaticLib")
|
||||
language("C++")
|
||||
links({
|
||||
"fmt"
|
||||
"fmt",
|
||||
})
|
||||
defines({
|
||||
})
|
||||
|
|
|
@ -53,6 +53,7 @@ SDLInputDriver::~SDLInputDriver() {
|
|||
}
|
||||
|
||||
X_STATUS SDLInputDriver::Setup() {
|
||||
XELOG_SDL_INIT()
|
||||
if (!TestSDLVersion()) {
|
||||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue