6#ifndef SWIFT_MISC_LOGHANDLER_H
7#define SWIFT_MISC_LOGHANDLER_H
21#include <QtMessageHandler>
27#include "misc/tokenbucket.h"
45 ~CLogHandler()
override;
52 void install(
bool skipIfAlreadyInstalled =
false);
97 friend class CLogPatternHandler;
99 QtMessageHandler m_oldHandler =
nullptr;
100 bool m_enableFallThrough =
true;
102 using PatternPair = std::pair<CLogPattern, CLogPatternHandler *>;
105 void removePatternHandler(CLogPatternHandler *);
128 m_inheritFallThrough =
false;
129 m_enableFallThrough = enable;
130 m_subscriptionNeedsUpdate =
true;
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>
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.
CLogPatternHandler * handlerForValidation()
Return a pattern handler for subscribing to all validation warnings and errors.
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.
static CLogHandler * instance()
Return pointer to the CLogHandler singleton.
void subscriptionAdded(const swift::misc::CLogPattern &pattern)
Emitted when an object subscribes to a pattern of log messages.
CLogPatternHandler * handlerForCategory(const CLogCategory &category)
Return a pattern handler for subscribing to all messages which contain the given category.
QList< CLogPattern > getAllSubscriptions() const
Returns all log patterns for which there are currently subscribed log pattern handlers.
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.
void subscriptionRemoved(const swift::misc::CLogPattern &pattern)
Emitted when an object unsubscribes from a pattern of log messages.
CLogPatternHandler * handlerForPattern(const CLogPattern &pattern)
Return a pattern handler for subscribing to all messages which match the given pattern.
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.
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.
static constexpr auto SeverityWarning
Status severities.
Free functions in swift::misc.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QThread * thread() const const
QThread * currentThread()
#define SWIFT_MISC_EXPORT
Export a class or function from the library.