Skip to content

Commit

Permalink
Log all Qt messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Nov 26, 2016
1 parent 87959b9 commit 5b9997f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,46 @@

Q_DECLARE_METATYPE(QByteArray*)

#if QT_VERSION < 0x050000
# define INSTALL_MESSAGE_HANDLER qInstallMsgHandler
#else
# define INSTALL_MESSAGE_HANDLER qInstallMessageHandler
#endif

namespace {

#if QT_VERSION < 0x050000
void messageHandler(QtMsgType type, const char *msg)
{
const QString message = msg;
#else
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
const QString message = QString("%1 (%2:%3, %4)")
.arg(msg, context.file, QString::number(context.line), context.function);
#endif

switch (type) {
case QtDebugMsg:
log("QtDebug: " + message, LogDebug);
break;
#if QT_VERSION >= 0x050000
case QtInfoMsg:
log("QtInfo: " + message, LogDebug);
break;
#endif
case QtWarningMsg:
log("QtWarning: " + message, LogDebug);
break;
case QtCriticalMsg:
log("QtCritical: " + message, LogError);
break;
case QtFatalMsg:
log("QtFatal: " + message, LogError);
abort();
}
}

int evaluate(const QString &functionName, const QStringList &arguments, int argc, char **argv)
{
App app( new QCoreApplication(argc, argv) );
Expand Down Expand Up @@ -140,6 +178,8 @@ QString getSessionName(const QStringList &arguments, int *skipArguments)

int main(int argc, char **argv)
{
INSTALL_MESSAGE_HANDLER(messageHandler);

const QStringList arguments =
createPlatformNativeInterface()->getCommandLineArguments(argc, argv);

Expand Down

0 comments on commit 5b9997f

Please sign in to comment.