6 #ifndef SWIFT_MISC_LOGHANDLER_H
7 #define SWIFT_MISC_LOGHANDLER_H
14 #include <QMetaMethod>
15 #include <QMetaObject>
21 #include <QtMessageHandler>
27 #include "misc/tokenbucket.h"
31 class CLogPatternHandler;
52 void install(
bool skipIfAlreadyInstalled =
false);
99 QtMessageHandler m_oldHandler =
nullptr;
100 bool m_enableFallThrough =
true;
101 bool isFallThroughEnabled(
const QList<CLogPatternHandler *> &handlers)
const;
102 using PatternPair = std::pair<CLogPattern, CLogPatternHandler *>;
103 QList<PatternPair> m_patternHandlers;
104 QList<CLogPatternHandler *> handlersForMessage(
const CStatusMessage &message)
const;
127 Q_ASSERT(thread() == QThread::currentThread());
128 m_inheritFallThrough =
false;
129 m_enableFallThrough = enable;
130 m_subscriptionNeedsUpdate =
true;
142 Q_ASSERT(thread() == QThread::currentThread());
143 m_inheritFallThrough =
true;
144 m_subscriptionNeedsUpdate =
true;
166 template <
typename T,
typename F>
175 template <
typename F>
187 m_subscriptionNeedsUpdate =
true;
196 m_subscriptionNeedsUpdate =
true;
205 bool m_inheritFallThrough =
true;
206 bool m_enableFallThrough =
true;
207 bool m_isSubscribed =
false;
208 std::atomic<bool> m_subscriptionNeedsUpdate {
false };
209 QTimer m_subscriptionUpdateTimer;
210 void updateSubscription();
228 template <
typename T,
typename F>
231 QObject::connect(
this, &CLogSubscriber::ps_messageLogged, parent, slot);
258 QPointer<CLogPatternHandler> m_handler;
259 bool m_inheritFallThrough =
true;
260 bool m_enableFallThrough =
true;
static const QString & validation()
Validation.
A log category is an arbitrary string tag which can be attached to log messages.
Class for subscribing to log messages.
void localMessageLogged(const swift::misc::CStatusMessage &message)
Emitted when a message is logged in this process.
void enableConsoleOutput(bool enable)
Enable or disable the default Qt handler.
void subscriptionAdded(const swift::misc::CLogPattern &pattern)
Emitted when an object subscribes to a pattern of log messages.
QList< CLogPattern > getAllSubscriptions() const
Returns all log patterns for which there are currently subscribed log pattern handlers.
static CLogHandler * instance()
Return pointer to the CLogHandler singleton.
CLogPatternHandler * handlerForCategory(const CLogCategory &category)
Return a pattern handler for subscribing to all messages which contain the given category.
CLogPatternHandler * handlerForPattern(const CLogPattern &pattern)
Return a pattern handler for subscribing to all messages which match the given pattern.
void logLocalMessage(const swift::misc::CStatusMessage &message)
Called by our QtMessageHandler to log a message.
void logRemoteMessage(const swift::misc::CStatusMessage &message)
Called by the context to relay a message.
void remoteMessageLogged(const swift::misc::CStatusMessage &message)
Emitted when a log message is relayed from a different process.
void install(bool skipIfAlreadyInstalled=false)
Tell the CLogHandler to install itself with qInstallMessageHandler.
CLogPatternHandler * handlerForValidation()
Return a pattern handler for subscribing to all validation warnings and errors.
void subscriptionRemoved(const swift::misc::CLogPattern &pattern)
Emitted when an object unsubscribes from a pattern of log messages.
A class for subscribing to log messages which match particular patterns.
void connectNotify(const QMetaMethod &signal)
void disconnectNotify(const QMetaMethod &signal)
QMetaObject::Connection subscribe(T *receiver, F slot)
Convenience method to connect the messageLogged signal to a slot in the given receiver object.
void enableConsoleOutput(bool enable)
Enable or disable the default Qt handler for messages which match the relevant pattern.
QMetaObject::Connection subscribe(F slot)
Convenience method to connect the messageLogged signal to a functor.
void inheritConsoleOutput()
The policy of whether to enable or disable the default Qt handler for messages which match the releva...
void messageLogged(const swift::misc::CStatusMessage &message)
Emitted when a message is logged which matches the relevant pattern.
Value class for matching log messages based on their categories.
static CLogPattern exactMatch(const CLogCategory &category)
Returns a CLogPattern which will match any message with the given category.
A helper class for subscribing to log messages matching a particular pattern, with the ability to cha...
void enableConsoleOutput(bool enable)
Enable or disable the default Qt handler for messages which match the relevant pattern.
void inheritConsoleOutput()
The policy of whether to enable or disable the default Qt handler for messages which match the releva...
void changeSubscription(const CLogPattern &pattern)
Change the pattern which you want to subscribe to.
void unsubscribe()
Unsubscribe from all messages.
CLogSubscriber(QObject *parent=nullptr)
Default constructor, for when you're not interested in messages and just want to control the console ...
CLogSubscriber(T *parent, F slot)
Construct a subscriber which forwards messages to the given slot of parent.
Streamable status message, e.g.
constexpr static auto SeverityWarning
Status severities.
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.