Common/Log: Check format strings
Helps with catching incorrect format strings. PanicAlertFmt already uses FMT_STRING and fmt::make_args_checked.
This commit is contained in:
parent
7e9a2dcc72
commit
47c91696ee
|
@ -76,13 +76,14 @@ enum LOG_LEVELS
|
||||||
static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID";
|
static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID";
|
||||||
|
|
||||||
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||||
std::string_view format, const fmt::format_args& args);
|
fmt::string_view format, const fmt::format_args& args);
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename S, typename... Args>
|
||||||
void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const S& format,
|
||||||
std::string_view format, const Args&... args)
|
const Args&... args)
|
||||||
{
|
{
|
||||||
GenericLogFmtImpl(level, type, file, line, format, fmt::make_format_args(args...));
|
GenericLogFmtImpl(level, type, file, line, format,
|
||||||
|
fmt::make_args_checked<Args...>(format, args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...)
|
void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...)
|
||||||
|
@ -136,11 +137,11 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con
|
||||||
|
|
||||||
// fmtlib capable API
|
// fmtlib capable API
|
||||||
|
|
||||||
#define GENERIC_LOG_FMT(t, v, ...) \
|
#define GENERIC_LOG_FMT(t, v, format, ...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if (v <= MAX_LOGLEVEL) \
|
if (v <= MAX_LOGLEVEL) \
|
||||||
Common::Log::GenericLogFmt(v, t, __FILE__, __LINE__, __VA_ARGS__); \
|
Common::Log::GenericLogFmt(v, t, __FILE__, __LINE__, FMT_STRING(format), ##__VA_ARGS__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ERROR_LOG_FMT(t, ...) \
|
#define ERROR_LOG_FMT(t, ...) \
|
||||||
|
|
|
@ -81,7 +81,7 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
|
||||||
std::string_view format, const fmt::format_args& args)
|
fmt::string_view format, const fmt::format_args& args)
|
||||||
{
|
{
|
||||||
auto* instance = LogManager::GetInstance();
|
auto* instance = LogManager::GetInstance();
|
||||||
if (instance == nullptr)
|
if (instance == nullptr)
|
||||||
|
|
Loading…
Reference in New Issue