From af0c6f923323de1ab82270d9e88c0a0c7fc1afe6 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 31 Oct 2021 13:17:24 +0100 Subject: [PATCH] Logging: Use `stdout` unless critical or fatal, and flush stream --- ext/libstrawberry-common/core/logging.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/libstrawberry-common/core/logging.cpp b/ext/libstrawberry-common/core/logging.cpp index f722a882e..9c427e78c 100644 --- a/ext/libstrawberry-common/core/logging.cpp +++ b/ext/libstrawberry-common/core/logging.cpp @@ -125,8 +125,9 @@ class LoggedDebug : public DebugBase { static void MessageHandler(QtMsgType type, const QMessageLogContext&, const QString &message) { - if (strncmp(kMessageHandlerMagic, message.toLocal8Bit().data(), kMessageHandlerMagicLength) == 0) { - fprintf(stderr, "%s\n", message.toLocal8Bit().data() + kMessageHandlerMagicLength); + if (message.startsWith(kMessageHandlerMagic)) { + fprintf(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout, "%s\n", message.toUtf8().data() + kMessageHandlerMagicLength); + fflush(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout); return; } @@ -150,7 +151,8 @@ static void MessageHandler(QtMsgType type, const QMessageLogContext&, const QStr d << line.toLocal8Bit().constData(); if (d.buf_) { d.buf_->close(); - fprintf(stderr, "%s\n", d.buf_->buffer().data()); + fprintf(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout, "%s\n", d.buf_->buffer().data()); + fflush(type == QtCriticalMsg || type == QtFatalMsg ? stderr : stdout); } }