diff options
author | Kai Koehne <kai.koehne@digia.com> | 2014-07-18 11:48:56 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@digia.com> | 2014-07-18 13:25:16 +0200 |
commit | 203d53d7228ac67691d761ed482c6185fa6fa580 (patch) | |
tree | 69724f55f2021a06fe4ee8e6ec012458fe47fc4d /src/libs/installer | |
parent | 5ca8f4d7a4171a1dae355899fb4fa457d34489b1 (diff) |
Simplify logging
Let VerboseWriter solely handle logging to the destination file.
qt_message_handler takes the role of logging to cout. This allows
us to get rid of the twisted stream logic in utils.cpp, and
furthermore let us get rid of the buggy debugstream.
Change-Id: I5cf2e41b126a90025825a0d93f95b41d783ef22a
Task-number: QTIFW-524
Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
Reviewed-by: Niels Weber <niels.weber@digia.com>
Diffstat (limited to 'src/libs/installer')
-rw-r--r-- | src/libs/installer/init.cpp | 27 | ||||
-rw-r--r-- | src/libs/installer/utils.cpp | 42 | ||||
-rw-r--r-- | src/libs/installer/utils.h | 7 |
3 files changed, 17 insertions, 59 deletions
diff --git a/src/libs/installer/init.cpp b/src/libs/installer/init.cpp index 478d77ae8..036a595e1 100644 --- a/src/libs/installer/init.cpp +++ b/src/libs/installer/init.cpp @@ -143,29 +143,29 @@ static void initResources() } #endif -static QByteArray trimAndPrepend(QtMsgType type, const QByteArray &msg) +static QString trimAndPrepend(QtMsgType type, const QString &msg) { - QByteArray ba(msg); + QString ba(msg); // last character is a space from qDebug - if (ba.endsWith(' ')) + if (ba.endsWith(QLatin1Char(' '))) ba.chop(1); // remove quotes if the whole message is surrounded with them - if (ba.startsWith('"') && ba.endsWith('"')) + if (ba.startsWith(QLatin1Char('"')) && ba.endsWith(QLatin1Char('"'))) ba = ba.mid(1, ba.length() - 2); // prepend the message type, skip QtDebugMsg switch (type) { case QtWarningMsg: - ba.prepend("Warning: "); + ba.prepend(QStringLiteral("Warning: ")); break; case QtCriticalMsg: - ba.prepend("Critical: "); + ba.prepend(QStringLiteral("Critical: ")); break; case QtFatalMsg: - ba.prepend("Fatal: "); + ba.prepend(QStringLiteral("Fatal: ")); break; default: @@ -179,19 +179,18 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt // suppress warning from QPA minimal plugin if (msg.contains(QLatin1String("This plugin does not support propagateSizeHints"))) return; - QByteArray ba = trimAndPrepend(type, msg.toLocal8Bit()); + QString ba = trimAndPrepend(type, msg); if (type != QtDebugMsg) { ba += QString(QStringLiteral(" (%1:%2, %3)")).arg( QString::fromLatin1(context.file)).arg(context.line).arg( - QString::fromLatin1(context.function)).toLocal8Bit(); + QString::fromLatin1(context.function)); } - if (!VerboseWriter::instance()) - return; + if (VerboseWriter *log = VerboseWriter::instance()) + log->appendLine(ba); - verbose() << ba.constData() << std::endl; - if (!isVerbose() && type != QtDebugMsg) - std::cout << ba.constData() << std::endl << std::endl; + if (type != QtDebugMsg || isVerbose()) + std::cout << qPrintable(ba) << std::endl; if (type == QtFatalMsg) { QtMessageHandler oldMsgHandler = qInstallMessageHandler(0); diff --git a/src/libs/installer/utils.cpp b/src/libs/installer/utils.cpp index 5e706ab13..9d0648268 100644 --- a/src/libs/installer/utils.cpp +++ b/src/libs/installer/utils.cpp @@ -133,44 +133,6 @@ bool QInstaller::isVerbose() return verb; } -#ifdef Q_OS_WIN -class debugstream : public std::ostream -{ - class buf : public std::stringbuf - { - public: - buf() {} - - int sync() - { - std::string s = str(); - if (s[s.length() - 1] == '\n' ) - s[s.length() - 1] = '\0'; // remove \n - std::cout << s << std::endl; - str(std::string()); - return 0; - } - }; -public: - debugstream() : std::ostream(&b) {} -private: - buf b; -}; -#endif - -std::ostream &QInstaller::stdverbose() -{ - static std::fstream null; -#ifdef Q_OS_WIN - static debugstream stream; -#else - static std::ostream& stream = std::cout; -#endif - if (verb) - return stream; - return null; -} - std::ostream &QInstaller::operator<<(std::ostream &os, const QString &string) { return os << qPrintable(string); @@ -281,9 +243,9 @@ QInstaller::VerboseWriter *QInstaller::VerboseWriter::instance() return verboseWriter(); } -QInstaller::VerboseWriter &QInstaller::verbose() +void QInstaller::VerboseWriter::appendLine(const QString &msg) { - return *verboseWriter(); + stream << msg << endl; } #ifdef Q_OS_WIN diff --git a/src/libs/installer/utils.h b/src/libs/installer/utils.h index 879b29afc..8b6b31ea3 100644 --- a/src/libs/installer/utils.h +++ b/src/libs/installer/utils.h @@ -75,11 +75,8 @@ namespace QInstaller { void INSTALLER_EXPORT setVerbose(bool v); bool INSTALLER_EXPORT isVerbose(); - INSTALLER_EXPORT std::ostream& stdverbose(); INSTALLER_EXPORT std::ostream& operator<<(std::ostream &os, const QString &string); - class VerboseWriter; - INSTALLER_EXPORT VerboseWriter &verbose(); class INSTALLER_EXPORT VerboseWriter : public QObject { @@ -90,8 +87,8 @@ namespace QInstaller { static VerboseWriter *instance(); - inline VerboseWriter &operator<<(const char *t) { stdverbose() << t; stream << t; return *this; } - inline VerboseWriter &operator<<(std::ostream& (*f)(std::ostream &s)) { stdverbose() << *f; stream << "\n"; return *this; } + void appendLine(const QString &msg); + public slots: void setOutputStream(const QString &fileName); |