fix: Logger not printing project prefix properly

This commit is contained in:
WerWolv
2023-12-20 15:10:53 +01:00
parent a0c2dc43f7
commit e2ae567b9f
2 changed files with 6 additions and 6 deletions

View File

@@ -29,13 +29,13 @@ namespace hex::log {
std::vector<LogEntry>& getLogEntries();
[[maybe_unused]] void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level);
[[maybe_unused]] void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level, const char *projectName);
[[maybe_unused]] void print(const fmt::text_style &ts, const std::string &level, const std::string &fmt, auto && ... args) {
std::scoped_lock lock(impl::g_loggerMutex);
auto dest = impl::getDestination();
printPrefix(dest, ts, level);
printPrefix(dest, ts, level, IMHEX_PROJECT_NAME);
auto message = fmt::format(fmt::runtime(fmt), args...);
fmt::print(dest, "{}\n", message);

View File

@@ -62,7 +62,7 @@ namespace hex::log::impl {
return logEntries;
}
void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level) {
void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level, const char *projectName) {
const auto now = fmt::localtime(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
fmt::print(dest, "[{0:%H:%M:%S}] ", now);
@@ -72,10 +72,10 @@ namespace hex::log::impl {
else
fmt::print(dest, ts, "{0} ", level);
fmt::print(dest, "[{0}] ", IMHEX_PROJECT_NAME);
fmt::print(dest, "[{0}] ", projectName);
constexpr static auto ProjectNameLength = std::char_traits<char>::length(IMHEX_PROJECT_NAME);
fmt::print(dest, "{}", std::string(ProjectNameLength > 10 ? 0 : 10 - ProjectNameLength, ' '));
auto projectNameLength = std::string_view(projectName).length();
fmt::print(dest, "{}", std::string(projectNameLength > 10 ? 0 : 10 - projectNameLength, ' '));
}
void assertionHandler(bool expr, const char* exprString, const char* file, int line) {