Merge pull request #4099 from Dimon4eg/write_logs_to_Output_window_of_Visual_Studio

write logs to Output window of Visual Studio
This commit is contained in:
Matthieu Gallien 2022-01-12 11:35:22 +01:00 committed by GitHub
commit f2d075f3ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,6 +89,30 @@ bool Logger::isLoggingToFile() const
void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString &message)
{
const QString msg = qFormatLogMessage(type, ctx, message);
#if defined(Q_OS_WIN) && defined(QT_DEBUG)
// write logs to Output window of Visual Studio
{
QString prefix;
switch (type) {
case QtDebugMsg:
break;
case QtInfoMsg:
break;
case QtWarningMsg:
prefix = QStringLiteral("[WARNING] ");
break;
case QtCriticalMsg:
prefix = QStringLiteral("[CRITICAL ERROR] ");
break;
case QtFatalMsg:
prefix = QStringLiteral("[FATAL ERROR] ");
break;
}
auto msgW = QString(prefix + message).toStdWString();
msgW.append(L"\n");
OutputDebugString(msgW.c_str());
}
#endif
{
QMutexLocker lock(&_mutex);
_crashLogIndex = (_crashLogIndex + 1) % CrashLogSize;