Implemented fallback debug logging to console for Windows

This commit is contained in:
2026-05-31 23:37:51 -07:00
parent a941d43120
commit 9659be8fc6

View File

@@ -169,16 +169,32 @@ void KRContext::Log(log_level level, const std::string message_format, ...)
va_list args; va_list args;
va_start(args, message_format); va_start(args, message_format);
const int LOG_BUFFER_SIZE = 32768;
char log_buffer[LOG_BUFFER_SIZE];
vsnprintf(log_buffer, LOG_BUFFER_SIZE, message_format.c_str(), args);
if (s_log_callback) { if (s_log_callback) {
const int LOG_BUFFER_SIZE = 32768;
char log_buffer[LOG_BUFFER_SIZE];
vsnprintf(log_buffer, LOG_BUFFER_SIZE, message_format.c_str(), args);
s_log_callback(s_log_callback_user_data, std::string(log_buffer), level); s_log_callback(s_log_callback_user_data, std::string(log_buffer), level);
} else { } else {
#if defined(_WIN32) || defined(_WIN64)
if (level == LOG_LEVEL_INFORMATION) {
OutputDebugStringA("Kraken - INFO: ");
} else {
OutputDebugStringA("Kraken - ERROR: ");
}
OutputDebugStringA(log_buffer);
OutputDebugStringA("\n");
#else
FILE* out_file = level == LOG_LEVEL_INFORMATION ? stdout : stderr; FILE* out_file = level == LOG_LEVEL_INFORMATION ? stdout : stderr;
fprintf(out_file, "Kraken - INFO: "); if (level == LOG_LEVEL_INFORMATION) {
vfprintf(out_file, message_format.c_str(), args); fprintf(out_file, "Kraken - INFO: ");
} else {
fprintf(out_file, "Kraken - ERROR: ");
}
fprintf(out_file, log_buffer);
fprintf(out_file, "\n"); fprintf(out_file, "\n");
#endif
} }
va_end(args); va_end(args);