write logs to Output window of Visual Studio
authorDmytro Korchynskyi <kdl.dima@gmail.com>
Sat, 18 Dec 2021 14:29:35 +0000 (16:29 +0200)
committerDmytro Korchynskyi <kdl.dima@gmail.com>
Wed, 12 Jan 2022 09:59:34 +0000 (11:59 +0200)
Signed-off-by: Dmytro Korchynskyi <kdl.dima@gmail.com>
src/libsync/logger.cpp

index 2a90c976b3f2643069531121e4669a1dcfec7643..294ad2bb6b704da39f60d3e8b195a3869bf4e639 100644 (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;