Common/Log: Add basic fmt-capable functions to the interface.

Provides a basic extension to the interface to begin migration off of
the printf-based logging system.

Everything will go through macros with the same style naming as the old
logging system, except the macros will have the _FMT suffix, while the
migration is in process.

This allows for peacemeal migration over time instead of pulling
everything out and replacing it all in a single pull request, which
makes for much easier reviewing.
This commit is contained in:
Lioncash
2020-10-20 15:37:02 -04:00
parent dc5ae5ee66
commit 425f2aa013
4 changed files with 95 additions and 26 deletions

View File

@ -18,19 +18,19 @@ static ptrdiff_t s_path_cutoff_point = 0;
static void LogCallback(const char* format, ...)
{
if (!Common::Log::LogManager::GetInstance())
auto* instance = Common::Log::LogManager::GetInstance();
if (instance == nullptr)
return;
va_list args;
va_start(args, format);
const char* filename = va_arg(args, const char*) + s_path_cutoff_point;
int lineno = va_arg(args, int);
std::string adapted_format(StripSpaces(format + strlen("%s:%d:")));
Common::Log::LogManager::GetInstance()->LogWithFullPath(
Common::Log::LNOTICE, Common::Log::AUDIO, filename, lineno, adapted_format.c_str(), args);
const int lineno = va_arg(args, int);
const std::string adapted_format(StripSpaces(format + strlen("%s:%d:")));
const std::string message = StringFromFormatV(adapted_format.c_str(), args);
va_end(args);
instance->Log(Common::Log::LNOTICE, Common::Log::AUDIO, filename, lineno, message.c_str());
}
static void DestroyContext(cubeb* ctx)