void dfs::core::DDebugInitialiser:: myMessageHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &message) { #ifdef DFS_COPY_DEBUG_OUTPUT_TO_FILE { QTextStream stream(&editDebugOutputFile()); stream << qFormatLogMessage(type, ctx, message) << "\n"; #ifndef DFS_DEBUG_DO_NOT_FLUSH stream.flush(); #endif } #ifndef DFS_DEBUG_DO_NOT_FLUSH editDebugOutputFile().flush(); #endif #endif #ifndef DFS_DEBUG_DO_NOT_MIRROR QtMessageHandler formerMsgHandler = editFormerMessageHandler(); if(formerMsgHandler != NULL) { formerMsgHandler(type, ctx, message); } #endif }
void LoggingSystem::qtMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) { #ifndef QT_DEBUG // Redirect debug for now if (type == QtDebugMsg) type = QtInfoMsg; #endif QString formatted = qFormatLogMessage(type, context, msg); LoggingSystem* t = Get(); t->message(formatted, type); }
static void messageHandler(QtMsgType type, const QMessageLogContext & context, const QString &message) { static QBasicAtomicInt counter = Q_BASIC_ATOMIC_INITIALIZER(QTest::maxWarnings); if (QTest::TestLoggers::loggerCount() == 0) { // if this goes wrong, something is seriously broken. qInstallMessageHandler(oldMessageHandler); QTEST_ASSERT(QTest::TestLoggers::loggerCount() != 0); } if (handleIgnoredMessage(type, message)) // the message is expected, so just swallow it. return; QString msg = qFormatLogMessage(type, context, message); if (type != QtFatalMsg) { if (counter.load() <= 0) return; if (!counter.deref()) { QTest::TestLoggers::addMessage(QAbstractTestLogger::QSystem, QStringLiteral("Maximum amount of warnings exceeded. Use -maxwarnings to override.")); return; } } switch (type) { case QtDebugMsg: QTest::TestLoggers::addMessage(QAbstractTestLogger::QDebug, msg); break; case QtCriticalMsg: QTest::TestLoggers::addMessage(QAbstractTestLogger::QSystem, msg); break; case QtWarningMsg: QTest::TestLoggers::addMessage(QAbstractTestLogger::QWarning, msg); break; case QtFatalMsg: QTest::TestLoggers::addMessage(QAbstractTestLogger::QFatal, msg); /* Right now, we're inside the custom message handler and we're * being qt_message_output in qglobal.cpp. After we return from * this function, it will proceed with calling exit() and abort() * and hence crash. Therefore, we call these logging functions such * that we wrap up nicely, and in particular produce well-formed XML. */ QTestResult::addFailure("Received a fatal error.", "Unknown file", 0); QTestLog::leaveTestFunction(); QTestLog::stopLogging(); break; } }
void CReporterLogger::messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { Q_ASSERT(CReporterLogger::sm_LogType != CReporter::LogNone); QString logMessage = qFormatLogMessage(type, context, msg); // print nothing if message pattern didn't apply / was empty. // (still print empty lines, e.g. because message itself was empty) if (logMessage.isNull()) return; if (CReporterLogger::sm_LogType == CReporter::LogSyslog) { int msgLevel = LOG_DEBUG; switch (type) { case QtDebugMsg: msgLevel = LOG_DEBUG; break; case QtInfoMsg: msgLevel = LOG_INFO; break; case QtWarningMsg: msgLevel = LOG_WARNING; break; case QtCriticalMsg: msgLevel = LOG_CRIT; break; case QtFatalMsg: msgLevel = LOG_EMERG; break; }; syslog(msgLevel, "%s", logMessage.toLocal8Bit().constData()); } else if (CReporterLogger::sm_LogType == CReporter::LogFile) { CReporterLogger::sm_Instance->m_stream << logMessage << endl; } if (type == QtFatalMsg) { exit(1); } }
void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { Q_UNUSED(context); #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) QString logLine = qFormatLogMessage(type, context, msg); #else QString msgType; switch (type) { case QtDebugMsg: msgType = "debug"; break; case QtWarningMsg: msgType = "warning"; break; case QtCriticalMsg: msgType = "critical"; break; case QtFatalMsg: msgType = "fatal"; break; #if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 1)) case QtInfoMsg: msgType = "info"; break; #endif } // %{time hh:mm:ss.zzz} %{type} T#%{threadid} %{function} - %{message} QString time = QDateTime::currentDateTimeUtc().toString("hh:mm:ss.zzz"); QString logLine = QString("%1 %2 T#%3 %4 - %5") .arg(time).arg(msgType) .arg(0).arg(context.function) .arg(msg); #endif Helpers::Logger &logger = Helpers::Logger::getInstance(); logger.log(logLine); if (type == QtFatalMsg) { abort(); } }
void qtServiceLogDebug(QtMsgType type, const char* msg) #endif { static QMutex mutex; QMutexLocker locker(&mutex); #if defined(Q_OS_WIN32) const qulonglong processId = GetCurrentProcessId(); #else const qulonglong processId = getpid(); #endif QByteArray s(QTime::currentTime().toString("HH:mm:ss.zzz").toLatin1()); s += " ["; s += QByteArray::number(processId); s += "] "; if (!f) { #if defined(Q_OS_WIN32) f = new QFile("c:/service-debuglog.txt"); #else f = new QFile("/tmp/service-debuglog.txt"); #endif if (!f->open(QIODevice::WriteOnly | QIODevice::Append)) { delete f; f = 0; return; } QByteArray ps('\n' + s + "--- DEBUG LOG OPENED ---\n"); f->write(ps); } switch (type) { case QtWarningMsg: s += "WARNING: "; break; case QtCriticalMsg: s += "CRITICAL: "; break; case QtFatalMsg: s+= "FATAL: "; break; case QtDebugMsg: s += "DEBUG: "; break; default: // Nothing break; } #if QT_VERSION >= 0x050400 s += qFormatLogMessage(type, context, msg).toLocal8Bit(); #elif QT_VERSION >= 0x050000 s += msg.toLocal8Bit(); Q_UNUSED(context) #else s += msg; #endif s += '\n'; f->write(s); f->flush(); if (type == QtFatalMsg) { qtServiceCloseDebugLog(); exit(1); } }
static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, const QString &message) { auto logger = Logger::instance(); if (!logger->isNoop()) { logger->doLog( qFormatLogMessage(type, ctx, message) ) ; } }
void DebugLog::handleMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QString formattedMessage = qFormatLogMessage(type, context, msg); ui->textBrowser->append(formattedMessage); }