| 23 | static QMutex *logfile_mutex = Q_NULLPTR; |
| 24 | void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg); |
| 25 | void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
| 26 | { |
| 27 | Q_UNUSED(context) |
| 28 | logfile_mutex->lock(); |
| 29 | |
| 30 | QString level; |
| 31 | switch(type) |
| 32 | { |
| 33 | case QtDebugMsg: |
| 34 | level = QString("[D]"); |
| 35 | break; |
| 36 | |
| 37 | case QtInfoMsg: |
| 38 | level = QString("[I]"); |
| 39 | break; |
| 40 | |
| 41 | case QtWarningMsg: |
| 42 | level = QString("[W]"); |
| 43 | break; |
| 44 | |
| 45 | case QtCriticalMsg: |
| 46 | level = QString("[E]"); |
| 47 | break; |
| 48 | |
| 49 | case QtFatalMsg: |
| 50 | level = QString("[F]"); |
| 51 | } |
| 52 | |
| 53 | // QString context_info = QString("File:(%1) Line:(%2)").arg(QString(context.file)).arg(context.line); |
| 54 | QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"); |
| 55 | QString current_date = QString("[%1]").arg(current_date_time); |
| 56 | QString message = QString("%1%2 %3").arg(current_date).arg(level).arg(msg); |
| 57 | |
| 58 | QFile file("log.txt"); |
| 59 | file.open(QIODevice::WriteOnly | QIODevice::Append); |
| 60 | QTextStream text_stream(&file); |
| 61 | text_stream << message << "\r\n"; |
| 62 | file.flush(); |
| 63 | file.close(); |
| 64 | |
| 65 | #ifdef QT_NO_DEBUG |
| 66 | #else |
| 67 | fprintf(stderr, "%s\n", message.toLocal8Bit().constData()); |
| 68 | #endif |
| 69 | |
| 70 | logfile_mutex->unlock(); |
| 71 | } |
| 72 | #endif |
| 73 | |
| 74 | #if 0 |
nothing calls this directly
no outgoing calls
no test coverage detected