From d2c3f7a326fc2c3b5f844000e93d04367c4b60dd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Nov 2023 00:52:08 +0100 Subject: [PATCH] libcalamares: improve formatting of Qt error messages These come through without function information, but we can format them in one line by mis-using function info. --- src/libcalamares/utils/Logger.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 69eb9e431..145abc990 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -98,18 +98,19 @@ log_implementation( const char* msg, unsigned int debugLevel, const char* funcin logfile << date.toUtf8().data() << " - " << time.toUtf8().data() << " [" << debugLevel << "]: " << funcinfo << '\n'; } + if (msg) { logfile << date.toUtf8().data() << " - " << time.toUtf8().data() << " [" << debugLevel << (funcinfo ? "]: " : "]: ") << msg << '\n'; - + } logfile.flush(); if ( logLevelEnabled( debugLevel ) ) { if ( funcinfo ) { - std::cout << time.toUtf8().data() << " [" << debugLevel << "]: " << funcinfo << s_Continuation; + std::cout << time.toUtf8().data() << " [" << debugLevel << "]: " << funcinfo << (msg ? s_Continuation : ""); } // The endl is desired, since it also flushes (like the logfile, above) - std::cout << msg << std::endl; + std::cout << (msg ? msg : "") << std::endl; } } @@ -117,20 +118,25 @@ static void CalamaresLogHandler( QtMsgType type, const QMessageLogContext&, const QString& msg ) { unsigned int level = LOGVERBOSE; + const char * funcinfo = nullptr; switch ( type ) { case QtInfoMsg: level = LOGVERBOSE; + funcinfo = "INFO"; break; case QtDebugMsg: level = LOGDEBUG; + funcinfo = "DEBUG"; break; case QtWarningMsg: level = LOGWARNING; + funcinfo = "WARNING"; break; case QtCriticalMsg: case QtFatalMsg: level = LOGERROR; + funcinfo = "ERROR"; break; } @@ -139,7 +145,7 @@ CalamaresLogHandler( QtMsgType type, const QMessageLogContext&, const QString& m return; } - log_implementation( msg.toUtf8().constData(), level, nullptr ); + log_implementation( nullptr, level, (QString(funcinfo) + QStringLiteral(" (Qt): ") + msg).toUtf8().constData() ); } QString