| 26 | #include <QtGlobal> |
| 27 | |
| 28 | void logMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) |
| 29 | { |
| 30 | QString msgType; |
| 31 | switch (type) { |
| 32 | case QtInfoMsg: |
| 33 | msgType = "Info"; |
| 34 | break; |
| 35 | case QtDebugMsg: |
| 36 | msgType = "Debug"; |
| 37 | break; |
| 38 | case QtWarningMsg: |
| 39 | msgType = "Warning"; |
| 40 | break; |
| 41 | case QtCriticalMsg: |
| 42 | msgType = "Critical"; |
| 43 | break; |
| 44 | case QtFatalMsg: |
| 45 | msgType = "Fatal"; |
| 46 | break; |
| 47 | } |
| 48 | QDateTime timeStamp = QDateTime::currentDateTime(); |
| 49 | QString logMessage = QString("%1: %2: %3").arg(timeStamp.toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(msgType).arg(msg); |
| 50 | QFile logFile("log.txt"); |
| 51 | if (logFile.open(QIODevice::WriteOnly | QIODevice::Append)) { |
| 52 | QTextStream textStream(&logFile); |
| 53 | textStream << logMessage << Qt::endl; |
| 54 | }; |
| 55 | // Suppress compiler warning |
| 56 | (void)context; |
| 57 | } |
| 58 | |
| 59 | int main(int argc, char *argv[]) |
| 60 | { |
nothing calls this directly
no outgoing calls
no test coverage detected