From 173d138134b6e509446e436cac08945627da003b Mon Sep 17 00:00:00 2001 From: Martin Klapetek Date: Fri, 19 Jun 2015 17:55:21 +0200 Subject: [PATCH] [dialer] Install custom qDebug messages handler Now it logs into ~/dialer.log, this way it can be retrieved even if autostarted by Mission Control. --- dialer/src/main.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dialer/src/main.cpp b/dialer/src/main.cpp index 106a61df..2ba77bb4 100644 --- a/dialer/src/main.cpp +++ b/dialer/src/main.cpp @@ -47,8 +47,35 @@ #include #include +#include +#include + +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + // TODO: print it on stdout too? + QFile file("/home/phablet/dialer.log"); + + bool opened = file.open(QIODevice::WriteOnly | QIODevice::Append); + Q_ASSERT(opened); + + QTextStream out(&file); + out << QTime::currentTime().toString("hh:mm:ss.zzz "); + out << context.function << ":" << context.line << " "; + + switch (type) { + case QtDebugMsg: out << "DBG"; break; + case QtWarningMsg: out << "WRN"; break; + case QtCriticalMsg: out << "CRT"; break; + case QtFatalMsg: out << "FTL"; break; + } + + out << " " << msg << '\n'; + out.flush(); +} + int main(int argc, char **argv) { + qInstallMessageHandler(myMessageOutput); QCommandLineParser parser; QApplication app(argc, argv);