mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-04-26 13:05:34 -06:00
Logging: Add compile-time format checks
This commit is contained in:
parent
02383542b2
commit
3fcc88567c
@ -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({}, {:x})", channel, memory_getVirtualOffsetFromPointer(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({}, 0x{:08x})", channel, memory_getVirtualOffsetFromPointer(wpadInfo));
|
||||
|
||||
if (channel < InputManager::kMaxWPADControllers)
|
||||
{
|
||||
|
||||
@ -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()));
|
||||
}
|
||||
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)...);
|
||||
cemuLog_log(type, fmt::format(formatStr, std::forward<TArgs>(args)...));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
#define cemuLog_logDebugOnce(...) { static bool _not_first_call = false; if (!_not_first_call) { _not_first_call = true; cemuLog_logDebug(__VA_ARGS__); } }
|
||||
|
||||
// utility function for logging binary data as a hex dump
|
||||
|
||||
Loading…
Reference in New Issue
Block a user