CFileLogger: group messages by category.

This commit is contained in:
Mathew Sutcliffe
2016-12-05 19:36:26 +00:00
committed by Klaus Basan
parent 8e6422d2be
commit 6bfbaefdc8
4 changed files with 14 additions and 7 deletions

View File

@@ -69,13 +69,16 @@ namespace BlackMisc
if (statusMessage.isEmpty()) { return; } if (statusMessage.isEmpty()) { return; }
if (!m_logFile.isOpen()) { return; } if (!m_logFile.isOpen()) { return; }
if (! m_logPattern.match(statusMessage)) { return; } if (! m_logPattern.match(statusMessage)) { return; }
const QString categories = statusMessage.getCategoriesAsString();
if (categories != m_previousCategories)
{
writeContentToFile(QStringLiteral("\n[") % categories % QStringLiteral("]"));
m_previousCategories = categories;
}
const QString finalContent(QDateTime::currentDateTime().toString(QStringLiteral("hh:mm:ss ")) const QString finalContent(QDateTime::currentDateTime().toString(QStringLiteral("hh:mm:ss "))
% statusMessage.getSeverityAsString() % statusMessage.getSeverityAsString()
% ": " % ": "
% statusMessage.getMessage() % statusMessage.getMessage());
% " cat: "
% statusMessage.getCategoriesAsString()
);
writeContentToFile(finalContent); writeContentToFile(finalContent);
} }

View File

@@ -70,6 +70,7 @@ namespace BlackMisc
QTextStream m_stream; QTextStream m_stream;
QString m_applicationName; QString m_applicationName;
QString m_logPath; //!< Empty by default. Hence the working directory "." is used QString m_logPath; //!< Empty by default. Hence the working directory "." is used
QString m_previousCategories;
}; };
} }

View File

@@ -84,7 +84,10 @@ namespace BlackMisc
} }
while (isRepeatable()); while (isRepeatable());
if (!isValid) { CLogMessage(this).debug() << "Failed to match" << getDecoderType() << "in remaining METAR:" << metarString; } if (!isValid)
{
CLogMessage(static_cast<CMetarDecoder*>(nullptr)).debug() << "Failed to match" << getDecoderType() << "in remaining METAR:" << metarString;
}
return isValid; return isValid;
} }
}; };

View File

@@ -30,8 +30,9 @@ namespace BlackMisc
//! Metar Decoder //! Metar Decoder
class BLACKMISC_EXPORT CMetarDecoder : public QObject class BLACKMISC_EXPORT CMetarDecoder : public QObject
{ {
public: Q_OBJECT
public:
//! Default constructor //! Default constructor
CMetarDecoder(); CMetarDecoder();
@@ -44,7 +45,6 @@ namespace BlackMisc
private: private:
void allocateDecoders(); void allocateDecoders();
std::vector<std::unique_ptr<IMetarDecoderPart>> m_decoders; std::vector<std::unique_ptr<IMetarDecoderPart>> m_decoders;
}; };
} // namespace } // namespace