refs #489 Predefined log patterns with human readable names.

This commit is contained in:
Mathew Sutcliffe
2015-10-29 21:49:08 +00:00
parent 72f295447b
commit 07c873a7c1
2 changed files with 37 additions and 0 deletions

View File

@@ -12,6 +12,35 @@
namespace BlackMisc
{
const QHash<QString, CLogPattern> &CLogPattern::allHumanReadablePatterns()
{
static const QHash<QString, CLogPattern> patterns
{
{ "uncategorized (swift)", exactMatch(CLogCategory::uncategorized()) },
{ "validation", exactMatch(CLogCategory::validation()) },
{ "swift contexts", exactMatch(CLogCategory::context()) },
{ "swift context slots", exactMatch(CLogCategory::contextSlot()) },
{ "swift GUI", exactMatch(CLogCategory::guiComponent()) },
{ "swift downloads", exactMatch(CLogCategory::download()) },
{ "Qt library", startsWith("qt.") },
{ "uncategorized (other)", empty() }
};
return patterns;
}
const QStringList &CLogPattern::allHumanReadableNames()
{
static const QStringList names = allHumanReadablePatterns().keys();
return names;
}
const CLogPattern &CLogPattern::fromHumanReadableName(const QString &name)
{
static const CLogPattern empty {};
auto it = allHumanReadablePatterns().find(name);
return it == allHumanReadablePatterns().end() ? empty : *it;
}
CLogPattern::CLogPattern(Strategy strategy, const QSet<QString> &strings)
: m_strategy(strategy), m_strings(strings)
{

View File

@@ -34,6 +34,12 @@ namespace BlackMisc
public Mixin::Icon<CLogPattern>
{
public:
//! Get a list of human-readable names of predefined log patterns.
static const QStringList &allHumanReadableNames();
//! Return a predefined CLogPattern corresponding to the given human-readable name.
static const CLogPattern &fromHumanReadableName(const QString &name);
//! Default constructed CLogPattern will match any message.
CLogPattern();
@@ -121,6 +127,8 @@ namespace BlackMisc
const QString &getPrefix() const { Q_ASSERT(m_strategy == StartsWith && m_strings.size() == 1); return *m_strings.begin(); }
const QString &getSuffix() const { Q_ASSERT(m_strategy == EndsWith && m_strings.size() == 1); return *m_strings.begin(); }
const QString &getSubstring() const { Q_ASSERT(m_strategy == Contains && m_strings.size() == 1); return *m_strings.begin(); }
static const QHash<QString, CLogPattern> &allHumanReadablePatterns();
};
}