swift
Loading...
Searching...
No Matches
logpattern.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_LOGPATTERN_H
7#define SWIFT_MISC_LOGPATTERN_H
8
9#include <QDBusArgument>
10#include <QMetaType>
11#include <QSet>
12#include <QString>
13#include <QStringList>
14#include <QtGlobal>
15
16#include "misc/metaclass.h"
25#include "misc/statusmessage.h"
27#include "misc/variant.h"
28
29template <class Key, class T>
30class QHash;
31
32namespace swift::misc
33{
34 class CLogCategory;
35 class CLogCategoryList;
36
41 public mixin::MetaType<CLogPattern>,
42 public mixin::HashByMetaClass<CLogPattern>,
43 public mixin::EqualsByMetaClass<CLogPattern>,
44 public mixin::DBusOperators<CLogPattern>,
45 public mixin::DataStreamOperators<CLogPattern>,
46 public mixin::Index<CLogPattern>,
47 public mixin::String<CLogPattern>,
48 public mixin::Icon<CLogPattern>
49 {
50 public:
52 static const QStringList &allHumanReadableNames();
53
55 static const CLogPattern &fromHumanReadableName(const QString &name);
56
59
62
65
67 static CLogPattern exactMatch(const CLogCategory &category);
68
70 static CLogPattern anyOf(const CLogCategoryList &categories);
71
73 static CLogPattern allOf(const CLogCategoryList &categories);
74
76 static CLogPattern startsWith(const QString &prefix);
77
79 static CLogPattern endsWith(const QString &suffix);
80
82 static CLogPattern contains(const QString &substring);
83
85 static CLogPattern empty();
86
89
92
96
98 bool match(const CStatusMessage &message) const;
99
101 bool matches(const CVariant &message) const { return match(message.value<CStatusMessage>()); }
102
104 QSet<QString> getCategoryStrings() const { return m_strings; }
105
112 bool isProperSubsetOf(const CLogPattern &other) const;
113
115 QString convertToQString(bool i18n = false) const;
116
118 void marshallToDbus(QDBusArgument &argument) const;
119
121 void unmarshallFromDbus(const QDBusArgument &argument);
122
124 void marshalToDataStream(QDataStream &stream) const;
125
127 void unmarshalFromDataStream(QDataStream &stream);
128
129 private:
130 bool checkInvariants() const;
131
132 enum Strategy
133 {
134 Everything = 0,
135 ExactMatch,
136 AnyOf,
137 AllOf,
138 StartsWith,
139 EndsWith,
140 Contains,
141 Nothing
142 };
143
144 CLogPattern(Strategy strategy, const QSet<QString> &strings);
145
147 Strategy m_strategy;
148 QSet<QString> m_strings;
149
150 const QString &getString() const
151 {
152 Q_ASSERT(m_strategy == ExactMatch && m_strings.size() == 1);
153 return *m_strings.begin();
154 }
155 const QString &getPrefix() const
156 {
157 Q_ASSERT(m_strategy == StartsWith && m_strings.size() == 1);
158 return *m_strings.begin();
159 }
160 const QString &getSuffix() const
161 {
162 Q_ASSERT(m_strategy == EndsWith && m_strings.size() == 1);
163 return *m_strings.begin();
164 }
165 const QString &getSubstring() const
166 {
167 Q_ASSERT(m_strategy == Contains && m_strings.size() == 1);
168 return *m_strings.begin();
169 }
170
171 static const QHash<QString, CLogPattern> &allHumanReadablePatterns();
172
174 CLogPattern,
175 SWIFT_METAMEMBER(severities),
176 SWIFT_METAMEMBER(strategy),
177 SWIFT_METAMEMBER(strings));
178 };
179} // namespace swift::misc
180
181Q_DECLARE_METATYPE(swift::misc::CLogPattern)
182
183#endif // SWIFT_MISC_LOGPATTERN_H
A log category is an arbitrary string tag which can be attached to log messages.
Definition logcategory.h:28
A sequence of log categories.
Value class for matching log messages based on their categories.
Definition logpattern.h:49
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.
QSet< QString > getCategoryStrings() const
Technical category names matched by this pattern.
Definition logpattern.h:104
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.
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.
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.
bool matches(const CVariant &message) const
This class acts as a SharedState filter when stored in a CVariant.
Definition logpattern.h:101
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.
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...
Streamable status message, e.g.
swift::misc::StatusSeverity StatusSeverity
Status severities.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition variant.h:69
T value() const
Return the value converted to the type T.
Definition variant.h:154
CRTP class template which will generate marshalling operators for a derived class with its own marsha...
Definition mixindbus.h:39
CRTP class template to generate non-member QDataStream streaming operators.
CRTP class template from which a derived class can inherit operator== implemented by metaclass.
CRTP class template from which a derived class can inherit common methods dealing with hashing instan...
Definition mixinhash.h:48
CRTP class template from which a derived class can inherit icon-related functions.
Definition mixinicon.h:28
CRTP class template from which a derived class can inherit property indexing functions.
Definition mixinindex.h:40
CRTP class template from which a derived class can inherit common methods dealing with the metatype o...
CRTP class template from which a derived class can inherit string streaming operations.
Definition mixinstring.h:29
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition metaclass.h:52
Free functions in swift::misc.
QSet< T >::iterator begin()
qsizetype size() const const
#define SWIFT_MISC_EXPORT
Export a class or function from the library.