17 const QHash<QString, CLogPattern> &CLogPattern::allHumanReadablePatterns()
19 static const QHash<QString, CLogPattern> patterns {
56 {
"uncategorized (default)",
exactMatch(
"default") },
57 {
"uncategorized (none)",
empty() }
64 static const QStringList names = allHumanReadablePatterns().keys();
94 auto it = allHumanReadablePatterns().find(name);
95 return it == allHumanReadablePatterns().end() ?
empty : *it;
109 return { ExactMatch, { category.
toQString() } };
114 if (categories.
size() == 0)
118 if (categories.
size() == 1)
128 if (categories.
size() == 0)
132 if (categories.
size() == 1)
151 result.m_severities = { severity };
158 result.m_severities = severities;
165 result.m_severities.
clear();
166 switch (minimumSeverity)
179 bool CLogPattern::checkInvariants()
const
183 case Everything:
return m_strings.
isEmpty();
184 case ExactMatch:
return m_strings.
size() == 1;
185 case AnyOf:
return m_strings.
size() > 1;
186 case AllOf:
return m_strings.
size() > 1;
187 case StartsWith:
return m_strings.
size() == 1;
188 case EndsWith:
return m_strings.
size() == 1;
189 case Contains:
return m_strings.
size() == 1;
190 case Nothing:
return m_strings.
isEmpty();
191 default:
return false;
197 if (!checkInvariants())
211 case Everything:
return true;
214 return std::ranges::any_of(m_strings,
217 return std::ranges::all_of(m_strings,
234 if (!(checkInvariants() && other.checkInvariants()))
244 if (!other.m_severities.
contains(m_severities))
249 if (m_strategy == other.m_strategy && m_strings == other.m_strings)
253 return m_severities.size() < other.m_severities.
size();
277 if (m_strategy != Everything && other.m_strategy == Everything)
284 switch (other.m_strategy)
286 case AnyOf:
return other.m_strings.
contains(getString());
287 case StartsWith:
return getString().startsWith(other.getPrefix());
288 case EndsWith:
return getString().endsWith(other.getSuffix());
289 case Contains:
return getString().contains(other.getSubstring());
294 switch (other.m_strategy)
296 case AnyOf:
return other.m_strings.
contains(m_strings) && other.m_strings.
size() > m_strings.size();
298 return std::ranges::all_of(m_strings,
301 return std::ranges::all_of(m_strings, [&](
const QString &s) {
return s.
endsWith(other.getSuffix()); });
303 return std::ranges::all_of(m_strings,
309 switch (other.m_strategy)
311 case ExactMatch:
return m_strings.contains(other.getString());
312 case AnyOf:
return !(m_strings & other.m_strings).isEmpty();
313 case AllOf:
return m_strings.contains(other.m_strings) && m_strings.size() > other.m_strings.
size();
315 return std::ranges::any_of(m_strings,
318 return std::ranges::any_of(m_strings, [&](
const QString &s) {
return s.
endsWith(other.getSuffix()); });
320 return std::ranges::any_of(m_strings,
326 switch (other.m_strategy)
329 return getPrefix().startsWith(other.getPrefix()) && getPrefix().size() > other.getPrefix().
size();
330 case Contains:
return getPrefix().contains(other.getSubstring());
335 switch (other.m_strategy)
338 return getSuffix().endsWith(other.getSuffix()) && getSuffix().size() > other.getSuffix().
size();
339 case Contains:
return getSuffix().contains(other.getSubstring());
344 switch (other.m_strategy)
347 return getSubstring().contains(other.getSubstring()) &&
348 getSubstring().size() > other.getSubstring().
size();
361 QString categories = m_strings.values().join(
"|");
364 case Everything: strategy =
"all";
break;
365 case ExactMatch: strategy =
"exact match:" + categories;
break;
366 case AnyOf: strategy =
"any of:" + categories;
break;
367 case AllOf: strategy =
"all of:" + categories;
break;
368 case StartsWith: strategy =
"starts with:" + categories;
break;
369 case EndsWith: strategy =
"ends with:" + categories;
break;
370 case Contains: strategy =
"contains:" + categories;
break;
371 case Nothing: strategy =
"none";
break;
372 default: strategy =
"<invalid>";
break;
380 quint8 severities = 0;
381 for (
auto s : m_severities)
383 severities |= (1 <<
static_cast<int>(s));
386 argument << severities << m_strategy << m_strings.values();
391 quint8 severities {};
393 argument >> severities >> m_strategy >> strings;
396 m_severities.clear();
397 for (
int s : { 0, 1, 2, 3 })
399 if (severities & (1 << s))
408 quint8 severities = 0;
409 for (
auto s : m_severities)
411 severities |= (1 <<
static_cast<int>(s));
414 stream << severities << m_strategy << m_strings.values();
419 quint8 severities {};
421 stream >> severities >> m_strategy >> strings;
424 m_severities.clear();
425 for (
int s : { 0, 1, 2, 3 })
427 if (severities & (1 << s))
static const QString & modelGui()
Model UI.
static const QString & swiftDataTool()
swift data tool (aka mapping tool)
static const QString & verification()
Verification.
static const QString & wizard()
Wizard.
static const QString & startup()
Startup of application.
static const QString & driver()
Driver.
static const QString & mapping()
Mapping.
static const QString & contextSlot()
Context slots.
static const QString & services()
Core/base services such as caching etc.
static const QString & modelCache()
Model cache.
static const QString & download()
Generic downloads.
static const QString & swiftDbWebservice()
Webservice with swift DB.
static const QString & vatsimSpecific()
VATSIM specific.
static const QString & context()
Contexts.
static const QString & swiftPilotClient()
swift GUI
static const QString & guiComponent()
GUI components.
static const QString & worker()
Background task.
static const QString & matching()
Matching.
static const QString & flightPlan()
Flight plan.
static const QString & cmdLine()
Cmd.line parsing.
static const QString & fsd()
FSD specific.
static const QString & swiftCore()
swift core
static const QString & cache()
Cache.
static const QString & uncategorized()
Uncategorized.
static const QString & modelLoader()
Model loader.
static const QString & json()
JSON and JSON conversions.
static const QString & dbus()
DBus related.
static const QString & modelSetCache()
Model set cache.
static const QString & webservice()
Webservice.
static const QString & dataInconsistency()
Data inconsistency.
static const QString & settings()
Settings.
static const QString & validation()
Validation.
static const QString & interpolator()
Interpolator.
static const QString & plugin()
Plugin.
static const QString & network()
Network specific, but not necessarily one specific flight network.
A log category is an arbitrary string tag which can be attached to log messages.
bool startsWith(const QString &prefix) const
Returns true if the category string starts with the given prefix.
bool endsWith(const QString &suffix) const
Returns true if the category string ends with the given suffix.
bool contains(const QString &substring) const
Returns true if the category string contains the given substring.
A sequence of log categories.
QStringList toQStringList() const
Convert each of the categories to a QString and return the result as a QStringList.
static QStringList humanReadableNamesFrom(const CStatusMessage &message)
Human readable categories of message.
bool match(const CStatusMessage &message) const
Returns true if the given message matches this pattern.
static QStringList humanOrTechnicalCategoriesFrom(const CStatusMessage &message)
Human or machine readable categories of message.
static const CLogPattern & fromHumanReadableName(const QString &name)
Return a predefined CLogPattern corresponding to the given human-readable name.
QString convertToQString(bool i18n=false) const
Cast as QString.
CLogPattern withSeverities(const QSet< CStatusMessage::StatusSeverity > &severities) const
Returns a CLogPattern which will match the same messages as this one, but only with some given severi...
static CLogPattern endsWith(const QString &suffix)
Returns a CLogPattern which will match any message with a category which ends with the given suffix.
void unmarshallFromDbus(const QDBusArgument &argument)
Unmarshall without begin/endStructure, for when composed within another object.
static CLogPattern allOf(const CLogCategoryList &categories)
Returns a CLogPattern which will match any message with all of the given categories.
static const QStringList & allHumanReadableNames()
Get a list of human-readable names of predefined log patterns.
void marshallToDbus(QDBusArgument &argument) const
Marshall without begin/endStructure, for when composed within another object.
static CLogPattern exactMatch(const CLogCategory &category)
Returns a CLogPattern which will match any message with the given category.
CLogPattern withSeverity(CStatusMessage::StatusSeverity severity) const
Returns a CLogPattern which will match the same messages as this one, but only with a given severity.
static CLogPattern startsWith(const QString &prefix)
Returns a CLogPattern which will match any message with a category which starts with the given prefix...
static CLogPattern contains(const QString &substring)
Returns a CLogPattern which will match any message with a category which contains the given substring...
static CLogPattern empty()
Returns a CLogPattern which will match any message without a category.
void marshalToDataStream(QDataStream &stream) const
Marshal a value to a QDataStream.
bool isProperSubsetOf(const CLogPattern &other) const
Returns true if this pattern is a proper subset of the other pattern.
void unmarshalFromDataStream(QDataStream &stream)
Unmarshal a value from a QDataStream.
static CLogPattern anyOf(const CLogCategoryList &categories)
Returns a CLogPattern which will match any message with any of the given categories.
CLogPattern()
Default constructed CLogPattern will match any message.
CLogPattern withSeverityAtOrAbove(CStatusMessage::StatusSeverity minimumSeverity) const
Returns a CLogPattern which will match the same messages, but only with a severity at or above the gi...
bool containsBy(Predicate p) const
Return true if there is an element for which a given predicate returns true.
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
size_type size() const
Returns number of elements in the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
StatusSeverity getSeverity() const
Message severity.
const CLogCategoryList & getCategories() const
Message categories.
swift::misc::StatusSeverity StatusSeverity
Status severities.
static constexpr auto SeverityDebug
Status severities.
static QString severitiesToString(const QSet< StatusSeverity > &severities)
Severity set as string.
static constexpr auto SeverityWarning
Status severities.
QString toQString(bool i18n=false) const
Cast as QString.
Free functions in swift::misc.
QList< T >::iterator begin()
QList< T >::iterator end()
bool isEmpty() const const
void push_back(QList< T >::parameter_type value)
bool contains(const QSet< T > &other) const const
bool isEmpty() const const
qsizetype size() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const