From cf48632f89383c9f96346ef8d0ac794f611766a0 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Tue, 26 Jan 2021 15:58:42 +0200 Subject: Restructure logging utilities Create a singleton-pattern class as an encapsulation unit for holding and altering the state of debug printing attributes. Move related code from various places under a single umbrella header file for logging utilities, with some minor stylistic changes & cleanup. This acts as a preparatory change for providing non-blocking headless CLI runs when there is no TTY attached - that will be fixed in a follow-up change. Change-Id: Ib7f72cf75362c3ea6713058e92eda997d6df55c3 Reviewed-by: Katja Marttila --- src/libs/installer/init.cpp | 100 +----- src/libs/installer/installer.pro | 8 +- src/libs/installer/loggingutils.cpp | 505 ++++++++++++++++++++++++++++ src/libs/installer/loggingutils.h | 129 +++++++ src/libs/installer/packagemanagercore.cpp | 56 +-- src/libs/installer/packagemanagercore.h | 4 +- src/libs/installer/packagemanagercore_p.cpp | 3 +- src/libs/installer/packagemanagergui.cpp | 5 +- src/libs/installer/printoutput.cpp | 123 ------- src/libs/installer/printoutput.h | 42 --- src/libs/installer/progresscoordinator.cpp | 5 +- src/libs/installer/utils.cpp | 172 +--------- src/libs/installer/utils.h | 52 +-- src/libs/kdtools/filedownloader.cpp | 4 +- 14 files changed, 664 insertions(+), 544 deletions(-) create mode 100644 src/libs/installer/loggingutils.cpp create mode 100644 src/libs/installer/loggingutils.h delete mode 100644 src/libs/installer/printoutput.cpp delete mode 100644 src/libs/installer/printoutput.h (limited to 'src/libs') diff --git a/src/libs/installer/init.cpp b/src/libs/installer/init.cpp index c1326824a..4aa65296f 100644 --- a/src/libs/installer/init.cpp +++ b/src/libs/installer/init.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -47,24 +47,14 @@ #include "licenseoperation.h" #include "settingsoperation.h" #include "consumeoutputoperation.h" -#include "globals.h" +#include "loggingutils.h" #include "lib7z_facade.h" -#include "utils.h" #include "updateoperationfactory.h" #include "filedownloaderfactory.h" #include -#include - -#include - -#if defined(Q_OS_UNIX) -#include -#elif defined(Q_OS_WIN) -#include -#endif using namespace KDUpdater; using namespace QInstaller; @@ -76,84 +66,6 @@ static void initResources() } #endif -static bool s_outputRedirected = false; - -static QString trimAndPrepend(QtMsgType type, const QString &msg) -{ - QString ba(msg); - // last character is a space from qDebug - if (ba.endsWith(QLatin1Char(' '))) - ba.chop(1); - - // remove quotes if the whole message is surrounded with them - 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(QStringLiteral("Warning: ")); - break; - - case QtCriticalMsg: - ba.prepend(QStringLiteral("Critical: ")); - break; - - case QtFatalMsg: - ba.prepend(QStringLiteral("Fatal: ")); - break; - - default: - break; - } - return ba; -} - -// start timer on construction (so we can use it as static member) -class Uptime : public QElapsedTimer { -public: - Uptime() { start(); } -}; - -void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) -{ - // suppress warning from QPA minimal plugin - if (msg.contains(QLatin1String("This plugin does not support propagateSizeHints"))) - return; - - if (context.category == lcProgressIndicator().categoryName()) { - if (!s_outputRedirected) - std::cout << msg.toStdString() << "\r" << std::flush; - return; - } - - static Uptime uptime; - - QString ba; - if (context.category != lcPackageInfo().categoryName()) { - ba = QLatin1Char('[') + QString::number(uptime.elapsed()) + QStringLiteral("] "); - } - ba += trimAndPrepend(type, msg); - - if (type != QtDebugMsg && context.file) { - ba += QString(QStringLiteral(" (%1:%2, %3)")).arg( - QString::fromLatin1(context.file)).arg(context.line).arg( - QString::fromLatin1(context.function)); - } - - if (VerboseWriter *log = VerboseWriter::instance()) - log->appendLine(ba); - - if (type != QtDebugMsg || isVerbose()) - std::cout << qPrintable(ba) << std::endl; - - if (type == QtFatalMsg) { - QtMessageHandler oldMsgHandler = qInstallMessageHandler(nullptr); - qt_message_output(type, context, msg); - qInstallMessageHandler(oldMsgHandler); - } -} - /*! Initializes the 7z library and installer resources. Registers custom operations and installs a custom message handler. @@ -190,10 +102,8 @@ void QInstaller::init() FileDownloaderFactory::setFollowRedirects(true); -#if defined(Q_OS_UNIX) - s_outputRedirected = !isatty(fileno(stdout)); -#elif defined(Q_OS_WIN) - s_outputRedirected = (GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == FILE_TYPE_DISK); -#endif + auto messageHandler = [](QtMsgType type, const QMessageLogContext &context, const QString &msg) { + LoggingHandler::instance().messageHandler(type, context, msg); + }; qInstallMessageHandler(messageHandler); } diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro index 437ab002f..bc4fcbb39 100644 --- a/src/libs/installer/installer.pro +++ b/src/libs/installer/installer.pro @@ -44,6 +44,7 @@ win32:QT += winextras HEADERS += packagemanagercore.h \ aspectratiolabel.h \ + loggingutils.h \ packagemanagercore_p.h \ packagemanagergui.h \ binaryformat.h \ @@ -137,11 +138,11 @@ HEADERS += packagemanagercore.h \ repositorycategory.h \ componentselectionpage_p.h \ commandlineparser.h \ - commandlineparser_p.h \ - printoutput.h + commandlineparser_p.h SOURCES += packagemanagercore.cpp \ aspectratiolabel.cpp \ + loggingutils.cpp \ packagemanagercore_p.cpp \ packagemanagergui.cpp \ binaryformat.cpp \ @@ -216,8 +217,7 @@ SOURCES += packagemanagercore.cpp \ packagesource.cpp \ repositorycategory.cpp \ componentselectionpage_p.cpp \ - commandlineparser.cpp \ - printoutput.cpp + commandlineparser.cpp FORMS += proxycredentialsdialog.ui \ serverauthenticationdialog.ui diff --git a/src/libs/installer/loggingutils.cpp b/src/libs/installer/loggingutils.cpp new file mode 100644 index 000000000..bd3bdbc3d --- /dev/null +++ b/src/libs/installer/loggingutils.cpp @@ -0,0 +1,505 @@ +/************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "loggingutils.h" + +#include "component.h" +#include "localpackagehub.h" +#include "globals.h" +#include "fileutils.h" +#include "remoteclient.h" +#include "remotefileengine.h" + +#include +#include + +#include +#if defined(Q_OS_UNIX) +#include +#elif defined(Q_OS_WIN) +#include +#endif + +namespace QInstaller { + +/*! + \class QInstaller::LoggingHandler + \inmodule QtInstallerFramework + \brief The LoggingHandler class provides methods for manipulating the + application-wide verbosiveness and format of printed debug messages. + + The class also contains utility methods for printing common preformatted messages. +*/ + +/*! + \inmodule QtInstallerFramework + \class QInstaller::Uptime + \internal +*/ + +/*! + \inmodule QtInstallerFramework + \class QInstaller::VerboseWriter + \internal +*/ + +/*! + \inmodule QtInstallerFramework + \class QInstaller::VerboseWriterOutput + \internal +*/ + +/*! + \inmodule QtInstallerFramework + \class QInstaller::PlainVerboseWriterOutput + \internal +*/ + +/*! + \inmodule QtInstallerFramework + \class QInstaller::VerboseWriterAdminOutput + \internal +*/ + +/*! + \enum LoggingHandler::VerbosityLevel + \brief This enum holds the possible levels of output verbosity. + + \value Silent + \value Normal + \value Detailed + \value Minimum + Minimum possible verbosity level. Synonym for \c VerbosityLevel::Silent. + \value Maximum + Maximum possible verbosity level. Synonym for \c VerbosityLevel::Detailed. +*/ + +// start timer on construction (so we can use it as static member) +class Uptime : public QElapsedTimer { +public: + Uptime() { start(); } +}; + +/*! + \internal +*/ +LoggingHandler::LoggingHandler() + : m_verbLevel(VerbosityLevel::Silent) +{ +#if defined(Q_OS_UNIX) + m_outputRedirected = !isatty(fileno(stdout)); +#elif defined(Q_OS_WIN) + m_outputRedirected = (GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == FILE_TYPE_DISK); +#endif +} + +/*! + \internal +*/ +LoggingHandler::~LoggingHandler() +{ +} + +/*! + Prints out preformatted debug messages, warnings, critical and fatal error messages + specified by \a msg and \a type. The message \a context provides information about + the source code location the message was generated. +*/ +void LoggingHandler::messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + // suppress warning from QPA minimal plugin + if (msg.contains(QLatin1String("This plugin does not support propagateSizeHints"))) + return; + + if (context.category == lcProgressIndicator().categoryName()) { + if (!outputRedirected()) + std::cout << msg.toStdString() << "\r" << std::flush; + return; + } + + static Uptime uptime; + + QString ba; + if (context.category != lcPackageInfo().categoryName()) { + ba = QLatin1Char('[') + QString::number(uptime.elapsed()) + QStringLiteral("] "); + } + ba += trimAndPrepend(type, msg); + + if (type != QtDebugMsg && context.file) { + ba += QString(QStringLiteral(" (%1:%2, %3)")).arg( + QString::fromLatin1(context.file)).arg(context.line).arg( + QString::fromLatin1(context.function)); + } + + if (VerboseWriter *log = VerboseWriter::instance()) + log->appendLine(ba); + + if (type != QtDebugMsg || isVerbose()) + std::cout << qPrintable(ba) << std::endl; + + if (type == QtFatalMsg) { + QtMessageHandler oldMsgHandler = qInstallMessageHandler(nullptr); + qt_message_output(type, context, msg); + qInstallMessageHandler(oldMsgHandler); + } +} + +/*! + Trims the trailing space character and surrounding quotes from \a msg. + Also prepends the message \a type to the message. +*/ +QString LoggingHandler::trimAndPrepend(QtMsgType type, const QString &msg) const +{ + QString ba(msg); + // last character is a space from qDebug + if (ba.endsWith(QLatin1Char(' '))) + ba.chop(1); + + // remove quotes if the whole message is surrounded with them + 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(QStringLiteral("Warning: ")); + break; + + case QtCriticalMsg: + ba.prepend(QStringLiteral("Critical: ")); + break; + + case QtFatalMsg: + ba.prepend(QStringLiteral("Fatal: ")); + break; + + default: + break; + } + return ba; +} + +/*! + Returns the only instance of this class. +*/ +LoggingHandler &LoggingHandler::instance() +{ + static LoggingHandler instance; + return instance; +} + +/*! + Sets to verbose output if \a v is set to \c true. Calling this multiple + times increases or decreases the verbosity level accordingly. +*/ +void LoggingHandler::setVerbose(bool v) +{ + if (v) + m_verbLevel++; + else + m_verbLevel--; +} + +/*! + Returns \c true if the installer is set to verbose output. +*/ +bool LoggingHandler::isVerbose() const +{ + return m_verbLevel != VerbosityLevel::Silent; +} + +/*! + Returns the current verbosity level. +*/ +LoggingHandler::VerbosityLevel LoggingHandler::verboseLevel() const +{ + return m_verbLevel; +} + +/*! + Returns \c true if output is redirected, i.e. to a file. +*/ +bool LoggingHandler::outputRedirected() const +{ + return m_outputRedirected; +} + +/*! + Prints basic information about \a components. +*/ +void LoggingHandler::printComponentInfo(const QList components) const +{ + QDomDocument doc; + QDomElement root = doc.createElement(QLatin1String("updates")); + doc.appendChild(root); + + foreach (Component *component, components) { + QDomElement update = doc.createElement(QLatin1String("update")); + update.setAttribute(QLatin1String("name"), component->value(scDisplayName)); + update.setAttribute(QLatin1String("version"), component->value(scVersion)); + update.setAttribute(QLatin1String("size"), component->value(scUncompressedSize)); + update.setAttribute(QLatin1String("id"), component->value(scName)); + root.appendChild(update); + } + qCDebug(lcPackageInfo) << qPrintable(doc.toString(4)); +} + +/*! + Prints basic or more detailed information about local \a packages, + depending on the current verbosity level. +*/ +void LoggingHandler::printLocalPackageInformation(const QList &packages) const +{ + QDomDocument doc; + QDomElement root = doc.createElement(QLatin1String("localpackages")); + doc.appendChild(root); + foreach (KDUpdater::LocalPackage package, packages) { + QDomElement update = doc.createElement(QLatin1String("package")); + update.setAttribute(QLatin1String("name"), package.name); + update.setAttribute(QLatin1String("displayname"), package.title); + update.setAttribute(QLatin1String("version"), package.version); + if (verboseLevel() == VerbosityLevel::Detailed) { + update.setAttribute(QLatin1String("description"), package.description); + update.setAttribute(QLatin1String("dependencies"), package.dependencies.join(QLatin1Char(','))); + update.setAttribute(QLatin1String("autoDependencies"), package.autoDependencies.join(QLatin1Char(','))); + update.setAttribute(QLatin1String("virtual"), package.virtualComp); + update.setAttribute(QLatin1String("forcedInstallation"), package.forcedInstallation); + update.setAttribute(QLatin1String("checkable"), package.checkable); + update.setAttribute(QLatin1String("uncompressedSize"), package.uncompressedSize); + update.setAttribute(QLatin1String("installDate"), package.installDate.toString()); + update.setAttribute(QLatin1String("lastUpdateDate"), package.lastUpdateDate.toString()); + } + root.appendChild(update); + } + qCDebug(lcPackageInfo) << qPrintable(doc.toString(4)); +} + +/*! + Prints basic or more detailed information about available \a matchedPackages, + depending on the current verbosity level. If a package is also present in \a installedPackages, + the installed version will be included in printed information. +*/ +void LoggingHandler::printPackageInformation(const PackagesList &matchedPackages, const LocalPackagesHash &installedPackages) const +{ + QDomDocument doc; + QDomElement root = doc.createElement(QLatin1String("availablepackages")); + doc.appendChild(root); + foreach (Package *package, matchedPackages) { + const QString name = package->data(scName).toString(); + QDomElement update = doc.createElement(QLatin1String("package")); + update.setAttribute(QLatin1String("name"), name); + update.setAttribute(QLatin1String("displayname"), package->data(scDisplayName).toString()); + update.setAttribute(QLatin1String("version"), package->data(scVersion).toString()); + //Check if package already installed + if (installedPackages.contains(name)) + update.setAttribute(QLatin1String("installedVersion"), installedPackages.value(name).version); + if (verboseLevel() == VerbosityLevel::Detailed) { + update.setAttribute(QLatin1String("description"), package->data(scDescription).toString()); + update.setAttribute(QLatin1String("dependencies"), package->data(scDependencies).toString()); + update.setAttribute(QLatin1String("autoDependencies"), package->data(scAutoDependOn).toString()); + update.setAttribute(QLatin1String("virtual"), package->data(scVirtual).toString()); + update.setAttribute(QLatin1String("forcedInstallation"), package->data(QLatin1String("ForcedInstallation")).toString()); + update.setAttribute(QLatin1String("checkable"), package->data(scCheckable).toString()); + update.setAttribute(QLatin1String("default"), package->data(scDefault).toString()); + update.setAttribute(QLatin1String("essential"), package->data(scEssential).toString()); + update.setAttribute(QLatin1String("forcedUpdate"), package->data(scForcedUpdate).toString()); + update.setAttribute(QLatin1String("compressedsize"), package->data(QLatin1String("CompressedSize")).toString()); + update.setAttribute(QLatin1String("uncompressedsize"), package->data(QLatin1String("UncompressedSize")).toString()); + update.setAttribute(QLatin1String("releaseDate"), package->data(scReleaseDate).toString()); + update.setAttribute(QLatin1String("downloadableArchives"), package->data(scDownloadableArchives).toString()); + update.setAttribute(QLatin1String("licenses"), package->data(QLatin1String("Licenses")).toString()); + update.setAttribute(QLatin1String("script"), package->data(scScript).toString()); + update.setAttribute(QLatin1String("sortingPriority"), package->data(scSortingPriority).toString()); + update.setAttribute(QLatin1String("replaces"), package->data(scReplaces).toString()); + update.setAttribute(QLatin1String("requiresAdminRights"), package->data(scRequiresAdminRights).toString()); + } + root.appendChild(update); + } + qCDebug(lcPackageInfo) << qPrintable(doc.toString(4)); +} + +/*! + \internal +*/ +VerboseWriter::VerboseWriter() +{ + m_preFileBuffer.open(QIODevice::ReadWrite); + m_stream.setDevice(&m_preFileBuffer); + m_currentDateTimeAsString = QDateTime::currentDateTime().toString(); +} + +/*! + \internal +*/ +VerboseWriter::~VerboseWriter() +{ + if (m_preFileBuffer.isOpen()) { + PlainVerboseWriterOutput output; + (void)flush(&output); + } +} + +/*! + \internal +*/ +bool VerboseWriter::flush(VerboseWriterOutput *output) +{ + m_stream.flush(); + if (m_logFileName.isEmpty()) // binarycreator + return true; + if (!m_preFileBuffer.isOpen()) + return true; + //if the installer installed nothing - there is no target directory - where the logfile can be saved + if (!QFileInfo(m_logFileName).absoluteDir().exists()) + return true; + + QString logInfo; + logInfo += QLatin1String("************************************* Invoked: "); + logInfo += m_currentDateTimeAsString; + logInfo += QLatin1String("\n"); + + QBuffer buffer; + buffer.open(QIODevice::WriteOnly); + buffer.write(logInfo.toLocal8Bit()); + buffer.write(m_preFileBuffer.data()); + buffer.close(); + + if (output->write(m_logFileName, QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text, buffer.data())) { + m_preFileBuffer.close(); + m_stream.setDevice(nullptr); + return true; + } + return false; +} + +/*! + \internal +*/ +void VerboseWriter::setFileName(const QString &fileName) +{ + m_logFileName = fileName; +} + +Q_GLOBAL_STATIC(VerboseWriter, verboseWriter) + +/*! + \internal +*/ +VerboseWriter *VerboseWriter::instance() +{ + return verboseWriter(); +} + +/*! + \internal +*/ +void VerboseWriter::appendLine(const QString &msg) +{ + m_stream << msg << endl; +} + +/*! + \internal +*/ +VerboseWriterOutput::~VerboseWriterOutput() +{ +} + +/*! + \internal +*/ +bool PlainVerboseWriterOutput::write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) +{ + QFile output(fileName); + if (output.open(openMode)) { + output.write(data); + setDefaultFilePermissions(&output, DefaultFilePermissions::NonExecutable); + return true; + } + return false; +} + +/*! + \internal +*/ +bool VerboseWriterAdminOutput::write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) +{ + bool gainedAdminRights = false; + + if (!RemoteClient::instance().isActive()) { + m_core->gainAdminRights(); + gainedAdminRights = true; + } + + RemoteFileEngine file; + file.setFileName(fileName); + if (file.open(openMode)) { + file.write(data.constData(), data.size()); + file.close(); + if (gainedAdminRights) + m_core->dropAdminRights(); + return true; + } + + if (gainedAdminRights) + m_core->dropAdminRights(); + + return false; +} + +/*! + \internal + + Increments verbosity \a level. +*/ +LoggingHandler::VerbosityLevel &operator++(LoggingHandler::VerbosityLevel &level, int) +{ + const int i = static_cast(level) + 1; + level = (i > LoggingHandler::VerbosityLevel::Maximum) + ? LoggingHandler::VerbosityLevel::Maximum + : static_cast(i); + + return level; +} + +/*! + \internal + + Decrements verbosity \a level. +*/ +LoggingHandler::VerbosityLevel &operator--(LoggingHandler::VerbosityLevel &level, int) +{ + const int i = static_cast(level) - 1; + level = (i < LoggingHandler::VerbosityLevel::Minimum) + ? LoggingHandler::VerbosityLevel::Minimum + : static_cast(i); + + return level; +} + +} // namespace QInstaller diff --git a/src/libs/installer/loggingutils.h b/src/libs/installer/loggingutils.h new file mode 100644 index 000000000..a997a6d60 --- /dev/null +++ b/src/libs/installer/loggingutils.h @@ -0,0 +1,129 @@ +/************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#ifndef LOGGINGUTILS_H +#define LOGGINGUTILS_H + +#include "component.h" + +#include + +namespace QInstaller { + +class INSTALLER_EXPORT LoggingHandler +{ + Q_DISABLE_COPY(LoggingHandler) + Q_ENUMS(VerbosityLevel) + +public: + enum VerbosityLevel { + Silent = 0, + Normal = 1, + Detailed = 2, + Minimum = Silent, + Maximum = Detailed + }; + + static LoggingHandler &instance(); + void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); + + void setVerbose(bool v); + bool isVerbose() const; + VerbosityLevel verboseLevel() const; + bool outputRedirected() const; + + void printComponentInfo(const QList components) const; + void printLocalPackageInformation(const QList &packages) const; + void printPackageInformation(const PackagesList &matchedPackages, const LocalPackagesHash &installedPackages) const; + + friend VerbosityLevel &operator++(VerbosityLevel &level, int); + friend VerbosityLevel &operator--(VerbosityLevel &level, int); + +private: + LoggingHandler(); + ~LoggingHandler(); + + QString trimAndPrepend(QtMsgType type, const QString &msg) const; + +private: + VerbosityLevel m_verbLevel; + bool m_outputRedirected; +}; + +class INSTALLER_EXPORT VerboseWriterOutput +{ +public: + virtual bool write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) = 0; + +protected: + ~VerboseWriterOutput(); +}; + +class INSTALLER_EXPORT PlainVerboseWriterOutput : public VerboseWriterOutput +{ +public: + virtual bool write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) override; +}; + +class INSTALLER_EXPORT VerboseWriterAdminOutput : public VerboseWriterOutput +{ +public: + VerboseWriterAdminOutput(PackageManagerCore *core) : m_core(core) {} + + virtual bool write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) override; + +private: + PackageManagerCore *m_core; +}; + +class INSTALLER_EXPORT VerboseWriter +{ +public: + VerboseWriter(); + ~VerboseWriter(); + + static VerboseWriter *instance(); + + bool flush(VerboseWriterOutput *output); + + void appendLine(const QString &msg); + void setFileName(const QString &fileName); + +private: + QTextStream m_stream; + QBuffer m_preFileBuffer; + QString m_logFileName; + QString m_currentDateTimeAsString; +}; + +LoggingHandler::VerbosityLevel &operator++(LoggingHandler::VerbosityLevel &level, int); +LoggingHandler::VerbosityLevel &operator--(LoggingHandler::VerbosityLevel &level, int); + +} // namespace QInstaller + +#endif // LOGGINGUTILS_H diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index ca128c6ea..4a0d2c191 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -45,7 +45,7 @@ #include "settings.h" #include "installercalculator.h" #include "uninstallercalculator.h" -#include "printoutput.h" +#include "loggingutils.h" #include @@ -1202,40 +1202,6 @@ PackageManagerCore::PackageManagerCore(qint64 magicmaker, const QListgainAdminRights(); - gainedAdminRights = true; - } - - RemoteFileEngine file; - file.setFileName(fileName); - if (file.open(openMode)) { - file.write(data.constData(), data.size()); - file.close(); - if (gainedAdminRights) - m_core->dropAdminRights(); - return true; - } - - if (gainedAdminRights) - m_core->dropAdminRights(); - - return false; - } - -private: - PackageManagerCore *m_core; -}; - /*! Destroys the instance. */ @@ -2225,7 +2191,7 @@ void PackageManagerCore::listAvailablePackages(const QString ®exp) if (matchedPackages.count() == 0) qCDebug(QInstaller::lcInstallerInstallLog) << "No matching packages found."; else - QInstaller::printPackageInformation(matchedPackages, localInstalledPackages()); + LoggingHandler::instance().printPackageInformation(matchedPackages, localInstalledPackages()); } bool PackageManagerCore::componentUninstallableFromCommandLine(const QString &componentName) @@ -2321,7 +2287,7 @@ void PackageManagerCore::listInstalledPackages(const QString ®exp) if (re.match(package.name).hasMatch()) packages.append(package); } - QInstaller::printLocalPackageInformation(packages); + LoggingHandler::instance().printLocalPackageInformation(packages); } /*! @@ -3177,15 +3143,7 @@ bool PackageManagerCore::containsValue(const QString &key) const */ bool PackageManagerCore::isVerbose() const { - return QInstaller::isVerbose(); -} - -/*! - Returns verbose level. -*/ -VerbosityLevel PackageManagerCore::verboseLevel() const -{ - return QInstaller::verboseLevel(); + return LoggingHandler::instance().isVerbose(); } /*! @@ -3194,7 +3152,7 @@ VerbosityLevel PackageManagerCore::verboseLevel() const */ void PackageManagerCore::setVerbose(bool on) { - QInstaller::setVerbose(on); + LoggingHandler::instance().setVerbose(on); } PackageManagerCore::Status PackageManagerCore::status() const @@ -3562,7 +3520,7 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo component->setUninstalled(); const QString localPath = component->localTempPath(); - if (verboseLevel() == VerbosityLevel::Detailed) { + if (LoggingHandler::instance().verboseLevel() == LoggingHandler::Detailed) { static QString lastLocalPath; if (lastLocalPath != localPath) qCDebug(QInstaller::lcDeveloperBuild()) << "Url is:" << localPath; diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h index 70ec83f15..b83d8f05a 100644 --- a/src/libs/installer/packagemanagercore.h +++ b/src/libs/installer/packagemanagercore.h @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -278,8 +278,6 @@ public: bool isVerbose() const; void setVerbose(bool on); - VerbosityLevel verboseLevel() const; - Q_INVOKABLE bool gainAdminRights(); Q_INVOKABLE void dropAdminRights(); diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 7f4330ca8..274ea017b 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -49,6 +49,7 @@ #include "componentchecker.h" #include "globals.h" #include "binarycreator.h" +#include "loggingutils.h" #include "selfrestarter.h" #include "filedownloaderfactory.h" @@ -465,7 +466,7 @@ bool PackageManagerCorePrivate::buildComponentTree(QHash &c restoreCheckState(); - if (m_core->verboseLevel() == VerbosityLevel::Detailed) { + if (LoggingHandler::instance().verboseLevel() == LoggingHandler::Detailed) { foreach (QInstaller::Component *component, components) { const QStringList warnings = ComponentChecker::checkComponent(component); foreach (const QString &warning, warnings) diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp index beb8603a4..e9f3a42fa 100644 --- a/src/libs/installer/packagemanagergui.cpp +++ b/src/libs/installer/packagemanagergui.cpp @@ -41,6 +41,7 @@ #include "productkeycheck.h" #include "repositorycategory.h" #include "componentselectionpage_p.h" +#include "loggingutils.h" #include "sysinfo.h" #include "globals.h" @@ -2578,7 +2579,7 @@ void ReadyForInstallationPage::entering() QString htmlOutput; bool componentsOk = packageManagerCore()->calculateComponents(&htmlOutput); m_taskDetailsBrowser->setHtml(htmlOutput); - m_taskDetailsBrowser->setVisible(!componentsOk || isVerbose()); + m_taskDetailsBrowser->setVisible(!componentsOk || LoggingHandler::instance().isVerbose()); setComplete(componentsOk); QString spaceInfo; @@ -2719,7 +2720,7 @@ void PerformInstallationPage::entering() if (packageManagerCore()->settings().productImages().count() > 1) m_imageChangeTimer.start(); - if (isVerbose()) { + if (LoggingHandler::instance().isVerbose()) { m_performInstallationForm->toggleDetails(); } if (packageManagerCore()->isUninstaller()) { diff --git a/src/libs/installer/printoutput.cpp b/src/libs/installer/printoutput.cpp deleted file mode 100644 index 27281aaf0..000000000 --- a/src/libs/installer/printoutput.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#include "printoutput.h" - -#include "component.h" -#include "localpackagehub.h" -#include "globals.h" - -#include -#include - -namespace QInstaller -{ - -void printComponentInfo(const QList components) -{ - QDomDocument doc; - QDomElement root = doc.createElement(QLatin1String("updates")); - doc.appendChild(root); - - foreach (Component *component, components) { - QDomElement update = doc.createElement(QLatin1String("update")); - update.setAttribute(QLatin1String("name"), component->value(scDisplayName)); - update.setAttribute(QLatin1String("version"), component->value(scVersion)); - update.setAttribute(QLatin1String("size"), component->value(scUncompressedSize)); - update.setAttribute(QLatin1String("id"), component->value(scName)); - root.appendChild(update); - } - qCDebug(lcPackageInfo) << qPrintable(doc.toString(4)); -} - -void printLocalPackageInformation(const QList &packages) -{ - QDomDocument doc; - QDomElement root = doc.createElement(QLatin1String("localpackages")); - doc.appendChild(root); - foreach (KDUpdater::LocalPackage package, packages) { - QDomElement update = doc.createElement(QLatin1String("package")); - update.setAttribute(QLatin1String("name"), package.name); - update.setAttribute(QLatin1String("displayname"), package.title); - update.setAttribute(QLatin1String("version"), package.version); - if (verboseLevel() == VerbosityLevel::Detailed) { - update.setAttribute(QLatin1String("description"), package.description); - update.setAttribute(QLatin1String("dependencies"), package.dependencies.join(QLatin1Char(','))); - update.setAttribute(QLatin1String("autoDependencies"), package.autoDependencies.join(QLatin1Char(','))); - update.setAttribute(QLatin1String("virtual"), package.virtualComp); - update.setAttribute(QLatin1String("forcedInstallation"), package.forcedInstallation); - update.setAttribute(QLatin1String("checkable"), package.checkable); - update.setAttribute(QLatin1String("uncompressedSize"), package.uncompressedSize); - update.setAttribute(QLatin1String("installDate"), package.installDate.toString()); - update.setAttribute(QLatin1String("lastUpdateDate"), package.lastUpdateDate.toString()); - } - root.appendChild(update); - } - qCDebug(lcPackageInfo) << qPrintable(doc.toString(4)); -} - -void printPackageInformation(const PackagesList &matchedPackages, const LocalPackagesHash &installedPackages) -{ - QDomDocument doc; - QDomElement root = doc.createElement(QLatin1String("availablepackages")); - doc.appendChild(root); - foreach (Package *package, matchedPackages) { - const QString name = package->data(scName).toString(); - QDomElement update = doc.createElement(QLatin1String("package")); - update.setAttribute(QLatin1String("name"), name); - update.setAttribute(QLatin1String("displayname"), package->data(scDisplayName).toString()); - update.setAttribute(QLatin1String("version"), package->data(scVersion).toString()); - //Check if package already installed - if (installedPackages.contains(name)) - update.setAttribute(QLatin1String("installedVersion"), installedPackages.value(name).version); - if (verboseLevel() == VerbosityLevel::Detailed) { - update.setAttribute(QLatin1String("description"), package->data(scDescription).toString()); - update.setAttribute(QLatin1String("dependencies"), package->data(scDependencies).toString()); - update.setAttribute(QLatin1String("autoDependencies"), package->data(scAutoDependOn).toString()); - update.setAttribute(QLatin1String("virtual"), package->data(scVirtual).toString()); - update.setAttribute(QLatin1String("forcedInstallation"), package->data(QLatin1String("ForcedInstallation")).toString()); - update.setAttribute(QLatin1String("checkable"), package->data(scCheckable).toString()); - update.setAttribute(QLatin1String("default"), package->data(scDefault).toString()); - update.setAttribute(QLatin1String("essential"), package->data(scEssential).toString()); - update.setAttribute(QLatin1String("forcedUpdate"), package->data(scForcedUpdate).toString()); - update.setAttribute(QLatin1String("compressedsize"), package->data(QLatin1String("CompressedSize")).toString()); - update.setAttribute(QLatin1String("uncompressedsize"), package->data(QLatin1String("UncompressedSize")).toString()); - update.setAttribute(QLatin1String("releaseDate"), package->data(scReleaseDate).toString()); - update.setAttribute(QLatin1String("downloadableArchives"), package->data(scDownloadableArchives).toString()); - update.setAttribute(QLatin1String("licenses"), package->data(QLatin1String("Licenses")).toString()); - update.setAttribute(QLatin1String("script"), package->data(scScript).toString()); - update.setAttribute(QLatin1String("sortingPriority"), package->data(scSortingPriority).toString()); - update.setAttribute(QLatin1String("replaces"), package->data(scReplaces).toString()); - update.setAttribute(QLatin1String("requiresAdminRights"), package->data(scRequiresAdminRights).toString()); - } - root.appendChild(update); - } - qCDebug(lcPackageInfo) << qPrintable(doc.toString(4)); -} -} // namespace QInstaller - diff --git a/src/libs/installer/printoutput.h b/src/libs/installer/printoutput.h deleted file mode 100644 index b1767830a..000000000 --- a/src/libs/installer/printoutput.h +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Installer Framework. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************/ - -#ifndef PRINTOUTPUT_H -#define PRINTOUTPUT_H - -#include "component.h" - -#include - -namespace QInstaller { - void INSTALLER_EXPORT printComponentInfo(const QList components); - void INSTALLER_EXPORT printLocalPackageInformation(const QList &packages); - void INSTALLER_EXPORT printPackageInformation(const PackagesList &matchedPackages, const LocalPackagesHash &installedPackages); -} - -#endif // PRINTOUTPUT_H diff --git a/src/libs/installer/progresscoordinator.cpp b/src/libs/installer/progresscoordinator.cpp index 7af24cb77..01b92bff8 100644 --- a/src/libs/installer/progresscoordinator.cpp +++ b/src/libs/installer/progresscoordinator.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -35,6 +35,7 @@ #include "globals.h" #include "utils.h" +#include "loggingutils.h" using namespace QInstaller; @@ -312,7 +313,7 @@ void ProgressCoordinator::emitDownloadStatus(const QString &status) void ProgressCoordinator::printProgressPercentage(int progress) { - if (!isVerbose()) + if (!LoggingHandler::instance().isVerbose()) return; Q_ASSERT(m_progressSpinner->currentIndex < m_progressSpinner->spinnerChars.size()); diff --git a/src/libs/installer/utils.cpp b/src/libs/installer/utils.cpp index 76ce9a938..59be2171b 100644 --- a/src/libs/installer/utils.cpp +++ b/src/libs/installer/utils.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -51,37 +51,6 @@ #include #endif -/*! - \inmodule QtInstallerFramework - \class QInstaller::PlainVerboseWriterOutput - \internal -*/ - -/*! - \inmodule QtInstallerFramework - \class QInstaller::VerboseWriterOutput - \internal -*/ - -/*! - \inmodule QtInstallerFramework - \class QInstaller::VerboseWriter - \internal -*/ - -/*! - \enum QInstaller::VerbosityLevel - \brief This enum holds the possible levels of output verbosity. - - \value Silent - \value Normal - \value Detailed - \value Minimum - Minimum possible verbosity level. Synonym for \c VerbosityLevel::Silent. - \value Maximum - Maximum possible verbosity level. Synonym for \c VerbosityLevel::Detailed. -*/ - /*! \internal */ @@ -164,37 +133,6 @@ QStringList QInstaller::localeCandidates(const QString &locale_) return candidates; } - -static QInstaller::VerbosityLevel verbLevel = QInstaller::VerbosityLevel::Silent; - -/*! - Sets to verbose output if \a v is set to \c true. Calling this multiple - times increases or decreases the verbosity level accordingly. -*/ -void QInstaller::setVerbose(bool v) -{ - if (v) - verbLevel++; - else - verbLevel--; -} - -/*! - Returns \c true if the installer is set to verbose output. -*/ -bool QInstaller::isVerbose() -{ - return verbLevel != VerbosityLevel::Silent; -} - -/*! - Returns the current verbosity level. -*/ -QInstaller::VerbosityLevel QInstaller::verboseLevel() -{ - return verbLevel; -} - /*! Returns a list of mutually exclusive options passed to the \a parser, if there is at least one mutually exclusive pair of options set. Otherwise returns an empty @@ -295,84 +233,6 @@ QString QInstaller::replaceWindowsEnvironmentVariables(const QString &str) return res; } -QInstaller::VerboseWriter::VerboseWriter() -{ - preFileBuffer.open(QIODevice::ReadWrite); - stream.setDevice(&preFileBuffer); - currentDateTimeAsString = QDateTime::currentDateTime().toString(); -} - -QInstaller::VerboseWriter::~VerboseWriter() -{ - if (preFileBuffer.isOpen()) { - PlainVerboseWriterOutput output; - (void)flush(&output); - } -} - -bool QInstaller::VerboseWriter::flush(VerboseWriterOutput *output) -{ - stream.flush(); - if (logFileName.isEmpty()) // binarycreator - return true; - if (!preFileBuffer.isOpen()) - return true; - //if the installer installed nothing - there is no target directory - where the logfile can be saved - if (!QFileInfo(logFileName).absoluteDir().exists()) - return true; - - QString logInfo; - logInfo += QLatin1String("************************************* Invoked: "); - logInfo += currentDateTimeAsString; - logInfo += QLatin1String("\n"); - - QBuffer buffer; - buffer.open(QIODevice::WriteOnly); - buffer.write(logInfo.toLocal8Bit()); - buffer.write(preFileBuffer.data()); - buffer.close(); - - if (output->write(logFileName, QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text, buffer.data())) { - preFileBuffer.close(); - stream.setDevice(nullptr); - return true; - } - return false; -} - -void QInstaller::VerboseWriter::setFileName(const QString &fileName) -{ - logFileName = fileName; -} - - -Q_GLOBAL_STATIC(QInstaller::VerboseWriter, verboseWriter) - -QInstaller::VerboseWriter *QInstaller::VerboseWriter::instance() -{ - return verboseWriter(); -} - -void QInstaller::VerboseWriter::appendLine(const QString &msg) -{ - stream << msg << endl; -} - -QInstaller::VerboseWriterOutput::~VerboseWriterOutput() -{ -} - -bool QInstaller::PlainVerboseWriterOutput::write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) -{ - QFile output(fileName); - if (output.open(openMode)) { - output.write(data); - setDefaultFilePermissions(&output, DefaultFilePermissions::NonExecutable); - return true; - } - return false; -} - #ifdef Q_OS_WIN // taken from qcoreapplication_p.h template @@ -542,33 +402,3 @@ QString QInstaller::windowsErrorString(int errorCode) } #endif - -/*! - \internal - - Increments verbosity \a level. -*/ -QInstaller::VerbosityLevel &QInstaller::operator++(QInstaller::VerbosityLevel &level, int) -{ - const int i = static_cast(level) + 1; - level = (i > VerbosityLevel::Maximum) - ? VerbosityLevel::Maximum - : static_cast(i); - - return level; -} - -/*! - \internal - - Decrements verbosity \a level. -*/ -QInstaller::VerbosityLevel &QInstaller::operator--(QInstaller::VerbosityLevel &level, int) -{ - const int i = static_cast(level) - 1; - level = (i < VerbosityLevel::Minimum) - ? VerbosityLevel::Minimum - : static_cast(i); - - return level; -} diff --git a/src/libs/installer/utils.h b/src/libs/installer/utils.h index 0c32c1672..a22acd879 100644 --- a/src/libs/installer/utils.h +++ b/src/libs/installer/utils.h @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -46,14 +46,6 @@ QT_END_NAMESPACE namespace QInstaller { - enum INSTALLER_EXPORT VerbosityLevel { - Silent = 0, - Normal = 1, - Detailed = 2, - Minimum = Silent, - Maximum = Detailed - }; - void INSTALLER_EXPORT uiDetachedWait(int ms); bool INSTALLER_EXPORT startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid = 0); @@ -72,51 +64,9 @@ namespace QInstaller { QStringList INSTALLER_EXPORT localeCandidates(const QString &locale); - void INSTALLER_EXPORT setVerbose(bool v); - bool INSTALLER_EXPORT isVerbose(); - VerbosityLevel INSTALLER_EXPORT verboseLevel(); - QStringList INSTALLER_EXPORT checkMutualOptions(CommandLineParser &parser, const QStringList &options); INSTALLER_EXPORT std::ostream& operator<<(std::ostream &os, const QString &string); - - class INSTALLER_EXPORT VerboseWriterOutput - { - public: - virtual bool write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data) = 0; - - protected: - ~VerboseWriterOutput(); - }; - - class INSTALLER_EXPORT PlainVerboseWriterOutput : public VerboseWriterOutput - { - public: - virtual bool write(const QString &fileName, QIODevice::OpenMode openMode, const QByteArray &data); - }; - - class INSTALLER_EXPORT VerboseWriter - { - public: - VerboseWriter(); - ~VerboseWriter(); - - static VerboseWriter *instance(); - - bool flush(VerboseWriterOutput *output); - - void appendLine(const QString &msg); - void setFileName(const QString &fileName); - - private: - QTextStream stream; - QBuffer preFileBuffer; - QString logFileName; - QString currentDateTimeAsString; - }; - - VerbosityLevel &operator++(VerbosityLevel &level, int); - VerbosityLevel &operator--(VerbosityLevel &level, int); } #endif // QINSTALLER_UTILS_H diff --git a/src/libs/kdtools/filedownloader.cpp b/src/libs/kdtools/filedownloader.cpp index ea8fdd23b..4cccfd9ca 100644 --- a/src/libs/kdtools/filedownloader.cpp +++ b/src/libs/kdtools/filedownloader.cpp @@ -32,6 +32,7 @@ #include "fileutils.h" #include "utils.h" +#include "loggingutils.h" #include #include @@ -1401,7 +1402,8 @@ void KDUpdater::HttpDownloader::httpReqFinished() const QUrl url = d->http->url(); // Only print host information when the logging category is enabled // and output verbosity is set above standard level. - if (url.isValid() && QInstaller::lcServer().isDebugEnabled() && verboseLevel() == VerbosityLevel::Detailed) { + if (url.isValid() && QInstaller::lcServer().isDebugEnabled() + && LoggingHandler::instance().verboseLevel() == LoggingHandler::Detailed) { const QFileInfo fi(d->http->url().toString()); if (fi.suffix() != QLatin1String("sha1")){ const QString hostName = url.host(); -- cgit v1.2.3