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.
This commit is contained in:
Adriaan de Groot 2023-11-07 00:52:08 +01:00
parent b57db97412
commit d2c3f7a326

View File

@ -98,18 +98,19 @@ log_implementation( const char* msg, unsigned int debugLevel, const char* funcin
logfile << date.toUtf8().data() << " - " << time.toUtf8().data() << " [" << debugLevel << "]: " << funcinfo logfile << date.toUtf8().data() << " - " << time.toUtf8().data() << " [" << debugLevel << "]: " << funcinfo
<< '\n'; << '\n';
} }
if (msg) {
logfile << date.toUtf8().data() << " - " << time.toUtf8().data() << " [" << debugLevel << (funcinfo ? "]: " : "]: ") << msg << '\n'; logfile << date.toUtf8().data() << " - " << time.toUtf8().data() << " [" << debugLevel << (funcinfo ? "]: " : "]: ") << msg << '\n';
}
logfile.flush(); logfile.flush();
if ( logLevelEnabled( debugLevel ) ) if ( logLevelEnabled( debugLevel ) )
{ {
if ( funcinfo ) 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) // 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 ) CalamaresLogHandler( QtMsgType type, const QMessageLogContext&, const QString& msg )
{ {
unsigned int level = LOGVERBOSE; unsigned int level = LOGVERBOSE;
const char * funcinfo = nullptr;
switch ( type ) switch ( type )
{ {
case QtInfoMsg: case QtInfoMsg:
level = LOGVERBOSE; level = LOGVERBOSE;
funcinfo = "INFO";
break; break;
case QtDebugMsg: case QtDebugMsg:
level = LOGDEBUG; level = LOGDEBUG;
funcinfo = "DEBUG";
break; break;
case QtWarningMsg: case QtWarningMsg:
level = LOGWARNING; level = LOGWARNING;
funcinfo = "WARNING";
break; break;
case QtCriticalMsg: case QtCriticalMsg:
case QtFatalMsg: case QtFatalMsg:
level = LOGERROR; level = LOGERROR;
funcinfo = "ERROR";
break; break;
} }
@ -139,7 +145,7 @@ CalamaresLogHandler( QtMsgType type, const QMessageLogContext&, const QString& m
return; return;
} }
log_implementation( msg.toUtf8().constData(), level, nullptr ); log_implementation( nullptr, level, (QString(funcinfo) + QStringLiteral(" (Qt): ") + msg).toUtf8().constData() );
} }
QString QString