common/logging: Make logging get checked at compile time

- ensures log strings match the amount and type (if the format specifies an integer, for example) of the arguments
- if at any later point a runtime-generated string is used as the log format, FmtLogMessage might require an overload taking a fmt::runtime_format_string<> as the format argument type, everything else being equal. wrap the generated string with fmt::runtime() before passing to the LOG_X functio
This commit is contained in:
FearlessTobi 2024-02-26 20:58:17 +01:00
parent 1bec420695
commit ee8ba5965b
5 changed files with 4 additions and 13 deletions

View File

@ -343,7 +343,7 @@ void SetColorConsoleBackendEnabled(bool enabled) {
}
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
unsigned int line_num, const char* function, const char* format,
unsigned int line_num, const char* function, fmt::string_view format,
const fmt::format_args& args) {
if (!initialization_in_progress_suppress_logging) {
Impl::Instance().PushEntry(log_class, log_level, filename, line_num, function,

View File

@ -24,12 +24,12 @@ constexpr const char* TrimSourcePath(std::string_view source) {
/// Logs a message to the global logger, using fmt
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
unsigned int line_num, const char* function, const char* format,
unsigned int line_num, const char* function, fmt::string_view format,
const fmt::format_args& args);
template <typename... Args>
void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
const char* function, const char* format, const Args&... args) {
const char* function, fmt::format_string<Args...> format, const Args&... args) {
FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
fmt::make_format_args(args...));
}

View File

@ -105,12 +105,4 @@ VirtualDir PartitionFilesystem::GetParentDirectory() const {
return nullptr;
}
void PartitionFilesystem::PrintDebugInfo() const {
LOG_DEBUG(Service_FS, "Magic: {:.4}", pfs_header.magic);
LOG_DEBUG(Service_FS, "Files: {}", pfs_header.num_entries);
for (u32 i = 0; i < pfs_header.num_entries; i++) {
LOG_DEBUG(Service_FS, " > File {}: {} (0x{:X} bytes)", i,
pfs_files[i]->GetName(), pfs_files[i]->GetSize());
}
}
} // namespace FileSys

View File

@ -35,7 +35,6 @@ public:
std::vector<VirtualDir> GetSubdirectories() const override;
std::string GetName() const override;
VirtualDir GetParentDirectory() const override;
void PrintDebugInfo() const;
private:
struct Header {

View File

@ -71,7 +71,7 @@ const char* GetType(GLenum type) {
void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
const GLchar* message, const void* user_param) {
const char format[] = "{} {} {}: {}";
constexpr std::string_view format = "{} {} {}: {}";
const char* const str_source = GetSource(source);
const char* const str_type = GetType(type);