mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 23:35:40 +08:00
Issue #15 Classes for sharing the history of log messages
This commit is contained in:
41
src/blackmisc/loghistory.cpp
Normal file
41
src/blackmisc/loghistory.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 2020
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#include "blackmisc/loghistory.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CLogHistory::CLogHistory(QObject *parent) : CListJournal(parent)
|
||||
{
|
||||
}
|
||||
|
||||
CLogHistorySource::CLogHistorySource(QObject *parent) : CListMutator(parent)
|
||||
{
|
||||
connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, [this](auto&&... args)
|
||||
{
|
||||
this->addElement(args...);
|
||||
});
|
||||
}
|
||||
|
||||
CLogHistoryReplica::CLogHistoryReplica(QObject* parent) : CListObserver(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void CLogHistoryReplica::onElementAdded(const CStatusMessage &msg)
|
||||
{
|
||||
emit elementAdded(msg);
|
||||
}
|
||||
|
||||
void CLogHistoryReplica::onElementsReplaced(const CStatusMessageList &msgs)
|
||||
{
|
||||
emit elementsReplaced(msgs);
|
||||
}
|
||||
}
|
||||
75
src/blackmisc/loghistory.h
Normal file
75
src/blackmisc/loghistory.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/* Copyright (C) 2020
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_LOGHISTORY_H
|
||||
#define BLACKMISC_LOGHISTORY_H
|
||||
|
||||
#include "blackmisc/sharedstate/datalink.h"
|
||||
#include "blackmisc/sharedstate/listjournal.h"
|
||||
#include "blackmisc/sharedstate/listmutator.h"
|
||||
#include "blackmisc/sharedstate/listobserver.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/logpattern.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* Records all log messages to a list that persists for the lifetime of the application.
|
||||
*/
|
||||
class BLACKMISC_EXPORT CLogHistory : public SharedState::CListJournal<CStatusMessageList>
|
||||
{
|
||||
Q_OBJECT
|
||||
BLACK_SHARED_STATE_CHANNEL("swift.log.history")
|
||||
|
||||
public:
|
||||
//! Constructor.
|
||||
CLogHistory(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Allows distributed insertion of log messages into a central CLogHistory.
|
||||
*/
|
||||
class BLACKMISC_EXPORT CLogHistorySource : public SharedState::CListMutator<CStatusMessageList>
|
||||
{
|
||||
Q_OBJECT
|
||||
BLACK_SHARED_STATE_CHANNEL("swift.log.history")
|
||||
|
||||
public:
|
||||
//! Constructor.
|
||||
CLogHistorySource(QObject *parent = nullptr);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Allows distributed access to the log messages of a central CLogHistory.
|
||||
*/
|
||||
class BLACKMISC_EXPORT CLogHistoryReplica : public SharedState::CListObserver<CStatusMessageList, CLogPattern>
|
||||
{
|
||||
Q_OBJECT
|
||||
BLACK_SHARED_STATE_CHANNEL("swift.log.history")
|
||||
|
||||
public:
|
||||
//! Constructor.
|
||||
CLogHistoryReplica(QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
//! Signal emitted for each new log message.
|
||||
void elementAdded(const BlackMisc::CStatusMessage &msg);
|
||||
|
||||
//! Signal emitted when the whole history is updated wholesale.
|
||||
void elementsReplaced(const BlackMisc::CStatusMessageList &msgs);
|
||||
|
||||
private:
|
||||
virtual void onElementAdded(const CStatusMessage &msg) override final;
|
||||
virtual void onElementsReplaced(const CStatusMessageList &msgs) override final;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -328,7 +328,7 @@ namespace BlackMisc
|
||||
QString categories = m_strings.values().join("|"); // clazy:exclude=container-anti-pattern
|
||||
switch (m_strategy)
|
||||
{
|
||||
case Everything: strategy = "none"; break;
|
||||
case Everything: strategy = "all"; break;
|
||||
case ExactMatch: strategy = "exact match:" + categories; break;
|
||||
case AnyOf: strategy = "any of:" + categories; break;
|
||||
case AllOf: strategy = "all of:" + categories; break;
|
||||
|
||||
@@ -93,6 +93,9 @@ namespace BlackMisc
|
||||
//! Returns true if the given message matches this pattern.
|
||||
bool match(const CStatusMessage &message) const;
|
||||
|
||||
//! This class acts as a SharedState filter when stored in a CVariant.
|
||||
bool matches(const CVariant &message) const { return match(message.to<CStatusMessage>()); }
|
||||
|
||||
//! Returns true if this pattern is a proper subset of the other pattern.
|
||||
//! \see https://en.wikipedia.org/wiki/Proper_subset
|
||||
//! \details Pattern A is a proper subset of pattern B iff pattern B would match every category which pattern A matches,
|
||||
|
||||
Reference in New Issue
Block a user