From 95a82f37a0f2f793ae283f12fa630891595ee0e1 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 10 Nov 2016 00:50:45 +0000 Subject: [PATCH] refs #800 QtInfoMsg severity was added in Qt 5.5, we can remove the category suffix workaround. --- src/blackmisc/logmessage.cpp | 35 +++------------------------------ src/blackmisc/logmessage.h | 31 ----------------------------- src/blackmisc/statusmessage.cpp | 21 +++++++++----------- src/xbus/utils.h | 4 ++++ 4 files changed, 16 insertions(+), 75 deletions(-) diff --git a/src/blackmisc/logmessage.cpp b/src/blackmisc/logmessage.cpp index ae0b1e877..5eed72bd0 100644 --- a/src/blackmisc/logmessage.cpp +++ b/src/blackmisc/logmessage.cpp @@ -42,16 +42,7 @@ namespace BlackMisc QByteArray CLogMessage::qtCategory() const { - if (m_categories.isEmpty()) - { - return {}; - } - else - { - QString category = m_categories.toQString(); - if (m_severity == CStatusMessage::SeverityDebug) { category = CLogMessageHelper::addDebugFlag(category); } - return category.toLatin1(); - } + return m_categories.toQString().toLatin1(); } QDebug CLogMessage::ostream(const QByteArray &category) const @@ -62,7 +53,7 @@ namespace BlackMisc { default: case CStatusMessage::SeverityDebug: return m_logger.debug(); - case CStatusMessage::SeverityInfo: return m_logger.debug(); + case CStatusMessage::SeverityInfo: return m_logger.info(); case CStatusMessage::SeverityWarning: return m_logger.warning(); case CStatusMessage::SeverityError: return m_logger.critical(); } @@ -73,33 +64,13 @@ namespace BlackMisc { default: case CStatusMessage::SeverityDebug: return m_logger.debug(QLoggingCategory(category.constData())); - case CStatusMessage::SeverityInfo: return m_logger.debug(QLoggingCategory(category.constData())); + case CStatusMessage::SeverityInfo: return m_logger.info(QLoggingCategory(category.constData())); case CStatusMessage::SeverityWarning: return m_logger.warning(QLoggingCategory(category.constData())); case CStatusMessage::SeverityError: return m_logger.critical(QLoggingCategory(category.constData())); } } } - //! Does category contain flag? - bool hasFlag(const QString &category, const QString &flag) - { - return category.section("/", 1, -1).split("/").contains(flag); - } - - //! Add flag to category - QString addFlag(QString category, const QString &flag) - { - if (category.isEmpty() || hasFlag(category, flag)) return category; - return category + "/" + flag; - } - QString CLogMessageHelper::addDebugFlag(const QString &category) { return addFlag(category, "debug"); } - QString CLogMessageHelper::stripFlags(const QString &category) { return category.section("/", 0, 0); } - bool CLogMessageHelper::hasDebugFlag(const QString &category) - { - return hasFlag(category, "debug") || category.isEmpty() - || (QLoggingCategory::defaultCategory() && category == QLoggingCategory::defaultCategory()->categoryName()); - } - void CLogMessage::preformatted(const CStatusMessage &statusMessage) { if (statusMessage.isEmpty()) { return; } // just skip empty messages diff --git a/src/blackmisc/logmessage.h b/src/blackmisc/logmessage.h index 595605465..cafdf5746 100644 --- a/src/blackmisc/logmessage.h +++ b/src/blackmisc/logmessage.h @@ -24,37 +24,6 @@ namespace BlackMisc { - /*! - * Helper with static methods for dealing with metadata embedded in log message category strings. - * - * There are certain aspects of log messages which cannot be represented in Qt's native log message machinery. - * Therefore we are forced to use a special encoding of the message category string to encode these aspects. - * - * An encoded category string consists of a plain category string with zero or more flag strings appended. - * The plain category and the flags are all separated by forward-slash characters ('/'). - * - * There are currently two flags: - * \li \c "debug" Qt only has 3 ordinary severities (debug, warning, critical), so we use QtMsgDebug for both - * debug and info messages, and we use this flag to distinguish between them. - * \li \c "redundant" To avoid handling the same message twice, this flag identifies a message which has already - * been directly returned as the return value of the method which generated it. - */ - class BLACKMISC_EXPORT CLogMessageHelper - { - public: - //! Deleted constructor. - CLogMessageHelper() = delete; - - //! Returns an encoded category string with the debug flag appended. - static QString addDebugFlag(const QString &category); - - //! Strips all flags from an encoded category string, returning only the plain category string. - static QString stripFlags(const QString &category); - - //! Returns true if the given encoded category string has the debug flag. - static bool hasDebugFlag(const QString &category); - }; - /*! * Class for emitting a log message. Works similar to the qDebug, qWarning, qCritical family of functions. * diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index b38a77fa5..02c8d1364 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -127,15 +127,16 @@ namespace BlackMisc CStatusMessage::CStatusMessage(QtMsgType type, const QMessageLogContext &context, const QString &message) : CStatusMessage(message.trimmed()) { - bool debug = CLogMessageHelper::hasDebugFlag(context.category); - auto categories = CLogMessageHelper::stripFlags(context.category); - m_categories = CLogCategoryList::fromQString(categories); + m_categories = CLogCategoryList::fromQString(context.category); switch (type) { default: case QtDebugMsg: - this->m_severity = debug ? SeverityDebug : SeverityInfo; + this->m_severity = SeverityDebug; + break; + case QtInfoMsg: + this->m_severity = SeverityInfo; break; case QtWarningMsg: this->m_severity = SeverityWarning; @@ -149,22 +150,18 @@ namespace BlackMisc void CStatusMessage::toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message) const { - auto category = m_categories.toQString(); - if (this->m_severity == SeverityDebug && ! category.isEmpty()) - { - category = CLogMessageHelper::addDebugFlag(category); - } - - *o_category = category; + *o_category = this->m_categories.toQString(); *o_message = this->getMessage(); switch (this->m_severity) { default: case SeverityDebug: - case SeverityInfo: *o_type = QtDebugMsg; break; + case SeverityInfo: + *o_type = QtInfoMsg; + break; case SeverityWarning: *o_type = QtWarningMsg; break; diff --git a/src/xbus/utils.h b/src/xbus/utils.h index 7b38d4e2f..d9f98042d 100644 --- a/src/xbus/utils.h +++ b/src/xbus/utils.h @@ -47,6 +47,10 @@ class QXPlaneMessageHandler std::sprintf(buffer, "%s:%d: Debug: %s\n", file.constData(), line, localMsg.constData()); XPLMDebugString(buffer); break; + case QtInfoMsg: + std::sprintf(buffer, "%s:%d: Info: %s\n", file.constData(), line, localMsg.constData()); + XPLMDebugString(buffer); + break; case QtWarningMsg: std::sprintf(buffer, "%s:%d: Warning: %s\n", file.constData(), line, localMsg.constData()); XPLMDebugString(buffer);