Update logging to check the format str at compile time

This commit is contained in:
SSimco
2025-08-29 21:18:09 +03:00
parent 5658466d84
commit 9bf84560a7
2 changed files with 19 additions and 31 deletions
+3 -3
View File
@@ -134,7 +134,7 @@ void padscoreExport_WPADGetInfoAsync(PPCInterpreter_t* hCPU)
ppcDefineParamU32(channel, 0);
ppcDefineParamStructPtr(wpadInfo, WPADInfo_t, 1);
ppcDefineParamMPTR(callbackFunc, 2);
cemuLog_log(LogType::InputAPI, "WPADGetInfoAsync({}, 0x{:08x}, 0x{:08x})", channel, fmt::ptr(wpadInfo), callbackFunc);
cemuLog_log(LogType::InputAPI, "WPADGetInfoAsync({}, {}, 0x{:08x})", channel, fmt::ptr(wpadInfo), callbackFunc);
if (channel < InputManager::kMaxWPADControllers)
{
@@ -170,7 +170,7 @@ void padscoreExport_WPADRead(PPCInterpreter_t* hCPU)
{
ppcDefineParamU32(channel, 0);
ppcDefineParamPtr(wpadStatus, WPADStatus_t, 1);
cemuLog_log(LogType::InputAPI, "WPADRead({}, {:x})", channel, fmt::ptr(wpadStatus));
cemuLog_log(LogType::InputAPI, "WPADRead({}, {})", channel, fmt::ptr(wpadStatus));
if (channel < InputManager::kMaxWPADControllers)
{
@@ -224,7 +224,7 @@ void padscoreExport_WPADGetInfo(PPCInterpreter_t* hCPU)
{
ppcDefineParamU32(channel, 0);
ppcDefineParamStructPtr(wpadInfo, WPADInfo_t, 1);
cemuLog_log(LogType::InputAPI, "WPADGetInfo({}, 0x{:08x})", channel, fmt::ptr(wpadInfo));
cemuLog_log(LogType::InputAPI, "WPADGetInfo({}, {})", channel, fmt::ptr(wpadInfo));
if (channel < InputManager::kMaxWPADControllers)
{
+16 -28
View File
@@ -78,43 +78,22 @@ bool cemuLog_log(LogType type, std::string_view text);
bool cemuLog_log(LogType type, std::u8string_view text);
void cemuLog_waitForFlush(); // wait until all log lines are written
template<typename T, typename ... TArgs>
bool cemuLog_log(LogType type, std::basic_string<T> formatStr, TArgs&&... args)
template<typename ... TArgs>
bool cemuLog_log(LogType type, fmt::format_string<TArgs...> formatStr, TArgs&&... args)
{
if (!cemuLog_isLoggingEnabled(type))
return false;
if constexpr (sizeof...(TArgs) == 0)
{
cemuLog_log(type, std::basic_string_view<T>(formatStr.data(), formatStr.size()));
return true;
}
else
{
const auto format_view = fmt::basic_string_view<T>(formatStr);
#if FMT_VERSION >= 110000
const auto text = fmt::vformat(format_view, fmt::make_format_args<fmt::buffered_context<T>>(args...));
#else
const auto text = fmt::vformat(format_view, fmt::make_format_args<fmt::buffer_context<T>>(args...));
#endif
cemuLog_log(type, std::basic_string_view(text.data(), text.size()));
}
cemuLog_log(type, fmt::format(formatStr, std::forward<TArgs>(args)...));
return true;
}
template<typename T, typename ... TArgs>
bool cemuLog_log(LogType type, const T* format, TArgs&&... args)
{
if (!cemuLog_isLoggingEnabled(type))
return false;
auto format_str = std::basic_string<T>(format);
return cemuLog_log(type, format_str, std::forward<TArgs>(args)...);
}
#define cemuLog_logOnce(...) { static bool _not_first_call = false; if (!_not_first_call) { _not_first_call = true; cemuLog_log(__VA_ARGS__); } }
// same as cemuLog_log, but only outputs in debug mode
template<typename TFmt, typename ... TArgs>
bool cemuLog_logDebug(LogType type, TFmt format, TArgs&&... args)
template<typename ... TArgs>
bool cemuLog_logDebug(LogType type, fmt::format_string<TArgs...> format, TArgs&&... args)
{
#ifdef CEMU_DEBUG_ASSERT
return cemuLog_log(type, format, std::forward<TArgs>(args)...);
@@ -123,6 +102,15 @@ bool cemuLog_logDebug(LogType type, TFmt format, TArgs&&... args)
#endif
}
inline bool cemuLog_logDebug(LogType type, std::string_view message)
{
#ifdef CEMU_DEBUG_ASSERT
return cemuLog_log(type, message);
#else
return false;
#endif
}
class LogCallbacks
{
public: