Skip to content

VERY experimental Nintendo Switch 2 emulator

C++

[common/logging] Fix long logs, remove clutter on Android logcat (#4310)

lizziee5b656e3725d
diff --git a/src/common/logging.cpp b/src/common/logging.cpp
index 5915cca862..ed12d52532 100644
--- a/src/common/logging.cpp
+++ b/src/common/logging.cpp
@@ -329,7 +329,7 @@ struct LogcatBackend : public Backend {
}
}();
auto const df = GetDirectFormatArgs(entry);
- __android_log_print(android_log_priority, "YuzuNative", CCB_PRINTF_FMT, df.time_seconds, df.time_fractional, df.class_name, df.level_name, entry.filename, entry.line_num, entry.function, entry.message);
+ __android_log_print(android_log_priority, "YuzuNative", "%s %s:%u:%s: %s", df.class_name, entry.filename, entry.line_num, entry.function, entry.message);
}
void Flush() noexcept override {}
};
@@ -428,21 +428,33 @@ void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, u
auto const flush = ::Settings::values.log_flush_line.GetValue();
char buffer[BUFSIZ];
auto result = fmt::vformat_to_n(buffer, sizeof(buffer) - 1, format, args);
- buffer[(std::min)(result.size, sizeof(buffer) - 1)] = '\0';
- logging_instance->ForEachBackend([=](Backend& backend) {
- backend.Write(Entry{
- .message = buffer,
- .message_len = (std::min)(result.size, sizeof(buffer) - 1),
- .timestamp = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - logging_instance->time_origin),
- .log_class = log_class,
- .log_level = log_level,
- .filename = TrimSourcePath(filename),
- .function = function,
- .line_num = line_num,
+ Entry e{
+ .message = nullptr,
+ .message_len = 0,
+ .timestamp = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - logging_instance->time_origin),
+ .log_class = log_class,
+ .log_level = log_level,
+ .filename = TrimSourcePath(filename),
+ .function = function,
+ .line_num = line_num,
+ };
+ if (result.size <= sizeof(buffer) - 1) {
+ buffer[(std::min)(result.size, sizeof(buffer) - 1)] = '\0';
+ e.message = buffer;
+ e.message_len = (std::min)(result.size, sizeof(buffer) - 1);
+ logging_instance->ForEachBackend([=](Backend& backend) {
+ backend.Write(e);
+ if (flush) backend.Flush();
});
- if (flush)
- backend.Flush();
- });
+ } else {
+ std::string s = fmt::vformat(format, args);
+ e.message = s.c_str();
+ e.message_len = s.size();
+ logging_instance->ForEachBackend([=](Backend& backend) {
+ backend.Write(e);
+ if (flush) backend.Flush();
+ });
+ }
}
}
} // namespace Common::Log
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 01ed3f8b1f..bc46b61bb4 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -126,9 +126,9 @@ void LogSettings() {
setting->UsingGlobal() ? '-' : 'C', TranslateCategory(category),
setting->GetLabel());
if (is_default)
- settings_list.push_back(fmt::format("{}: {}\n", name, setting->Canonicalize()));
+ settings_list.push_back(fmt::format("{}: {}", name, setting->Canonicalize()));
else
- settings_list.push_front(fmt::format("{}: {}\n", name, setting->Canonicalize()));
+ settings_list.push_front(fmt::format("{}: {}", name, setting->Canonicalize()));
}
}
}