Common/MsgHandler: Use caller's file and line number in log messages

This will assist with finding the source of a panic alert based on logs; before, Common\MsgHandler.cpp:113 (or similar) was always used.
This commit is contained in:
Pokechu22
2021-11-16 18:48:30 -08:00
parent f55571ee5d
commit c296c34e00
2 changed files with 20 additions and 15 deletions

View File

@ -107,10 +107,13 @@ std::string GetStringT(const char* string)
}
static bool ShowMessageAlert(std::string_view text, bool yes_no, Common::Log::LogType log_type,
MsgType style)
MsgType style, const char* file, int line)
{
const char* caption = GetCaption(style);
GENERIC_LOG_FMT(log_type, Common::Log::LogLevel::LERROR, "{}: {}", caption, text);
// Directly call GenericLogFmt rather than using the normal log macros so that we can use the
// caller's line file and line number
Common::Log::GenericLogFmt<2>(Common::Log::LogLevel::LERROR, log_type, file, line,
FMT_STRING("{}: {}"), caption, text);
// Panic alerts.
if (style == MsgType::Warning && s_abort_on_panic_alert)
@ -130,11 +133,11 @@ static bool ShowMessageAlert(std::string_view text, bool yes_no, Common::Log::Lo
// This is the first stop for gui alerts where the log is updated and the
// correct window is shown, when using fmt
bool MsgAlertFmtImpl(bool yes_no, MsgType style, Common::Log::LogType log_type,
fmt::string_view format, const fmt::format_args& args)
bool MsgAlertFmtImpl(bool yes_no, MsgType style, Common::Log::LogType log_type, const char* file,
int line, fmt::string_view format, const fmt::format_args& args)
{
const auto message = fmt::vformat(format, args);
return ShowMessageAlert(message, yes_no, log_type, style);
return ShowMessageAlert(message, yes_no, log_type, style, file, line);
}
} // namespace Common