mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
refs #800 QtInfoMsg severity was added in Qt 5.5, we can remove the category suffix workaround.
This commit is contained in:
committed by
Klaus Basan
parent
af066be740
commit
95a82f37a0
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user