| 1382 | } |
| 1383 | |
| 1384 | void br::Context::messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
| 1385 | { |
| 1386 | // Something about this method is not thread safe, and will lead to crashes if qDebug |
| 1387 | // statements are called from multiple threads. Unless we lock the whole thing... |
| 1388 | static QMutex generalLock; |
| 1389 | QMutexLocker locker(&generalLock); |
| 1390 | |
| 1391 | QString txt; |
| 1392 | if (type == QtDebugMsg) { |
| 1393 | if (Globals->quiet) return; |
| 1394 | txt = QString("%1\n").arg(msg); |
| 1395 | } else { |
| 1396 | switch (type) { |
| 1397 | case QtWarningMsg: txt = QString("Warning: %1\n" ).arg(msg); break; |
| 1398 | case QtCriticalMsg: txt = QString("Critical: %1\n").arg(msg); break; |
| 1399 | default: txt = QString("Fatal: %1\n" ).arg(msg); break; |
| 1400 | } |
| 1401 | txt += " SDK Path: " + Globals->sdkPath + "\n File: " + QString(context.file) + "\n Function: " + QString(context.function) + "\n Line: " + QString::number(context.line) + "\n"; |
| 1402 | } |
| 1403 | |
| 1404 | std::cerr << txt.toStdString(); |
| 1405 | Globals->mostRecentMessage = txt; |
| 1406 | |
| 1407 | if (Globals->logFile.isWritable()) { |
| 1408 | Globals->logFile.write(qPrintable(txt)); |
| 1409 | Globals->logFile.flush(); |
| 1410 | } |
| 1411 | |
| 1412 | if (type == QtFatalMsg) { |
| 1413 | #ifdef _WIN32 |
| 1414 | QCoreApplication::quit(); // abort() hangs the console on Windows for some reason related to the event loop not being exited |
| 1415 | #else // not _WIN32 |
| 1416 | abort(); // We abort so we can get a stack trace back to the code that triggered the message. |
| 1417 | #endif // _WIN32 |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | Context *br::Globals = NULL; |
| 1422 | |