From 433d2109d217cbbad97e430fe2bb1ea70dd67f2f Mon Sep 17 00:00:00 2001 From: Nathan Conway Date: Thu, 19 Feb 2026 22:08:14 -0500 Subject: [PATCH] finalize formatting --- components/platform/application.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/components/platform/application.cpp b/components/platform/application.cpp index f819b6ada5..86cb017563 100644 --- a/components/platform/application.cpp +++ b/components/platform/application.cpp @@ -1,5 +1,9 @@ #include "application.hpp" +#include +#include +#include + #include #include #include @@ -10,7 +14,7 @@ namespace Platform { - static void qtMessageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg) + static void qtMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) { Debug::Level level; switch (type) @@ -32,7 +36,25 @@ namespace Platform break; } - Log(level) << msg.toUtf8().constData(); + const bool nonDefaultCategory = context.category && std::string_view(context.category) != "default"; + // context.file and context.function are only populated in debug builds + // Qt strips them to nullptr in release + const bool hasLocation = context.file != nullptr; + + std::string formatted; + if (nonDefaultCategory) + { + // Show non-default categories + formatted += '['; + formatted += context.category; + formatted += "] "; + } + // += could null terminate, so use append with explicit size + const QByteArray utf8msg = msg.toUtf8(); + formatted.append(utf8msg.constData(), static_cast(utf8msg.size())); + if (hasLocation) + formatted += std::format(" ({}:{}, {})", context.file, context.line, context.function); + Log(level) << formatted; } Application::Application(int& argc, char* argv[])