From 81c6f744780fee7381e62a702aebba7a5ec4d6f3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 8 Jul 2019 09:00:56 +0200 Subject: gui/init: print loglevel for qDebug() and friends --- gui/init.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gui/init.cpp b/gui/init.cpp index 96cfcea9..1fd6ff4e 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -111,8 +111,20 @@ static void set_qt_style() # include #endif -static void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QString &msg) +static void qdebug_to_console(QtMsgType loglevel, const QMessageLogContext& ctx, const QString &msg) { + const char* level; + + switch (loglevel) + { + default: + case QtDebugMsg: level = "DEBUG "; break; + case QtWarningMsg: level = "WARN "; break; + case QtCriticalMsg: level = "CRIT "; break; + case QtFatalMsg: level = "FATAL "; break; + case QtInfoMsg: level = "INFO "; break; + } + #ifdef _WIN32 static_assert(sizeof(wchar_t) == sizeof(decltype(*msg.utf16()))); @@ -139,9 +151,9 @@ static void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QS #endif { if (ctx.file) - std::fprintf(stderr, "[%s:%d]: %ls\n", ctx.file, ctx.line, bytes); + std::fprintf(stderr, "%s[%s:%d]: %ls\n", level, ctx.file, ctx.line, bytes); else - std::fprintf(stderr, "%ls\n", bytes); + std::fprintf(stderr, "%s%ls\n", level, bytes); } std::fflush(stderr); } -- cgit v1.2.3