mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
Addded log categories / human readable pattern
This commit is contained in:
@@ -24,6 +24,12 @@ using namespace BlackCore::Settings;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
const CLogCategoryList &CThreadedReader::getLogCategories()
|
||||
{
|
||||
static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::worker() };
|
||||
return cats;
|
||||
}
|
||||
|
||||
CThreadedReader::CThreadedReader(QObject *owner, const QString &name) :
|
||||
CContinuousWorker(owner, name),
|
||||
m_updateTimer(new QTimer(this))
|
||||
@@ -31,6 +37,11 @@ namespace BlackCore
|
||||
m_toggleConnection = connect(this->m_updateTimer, &QTimer::timeout, this, &CThreadedReader::ps_toggleInterval);
|
||||
}
|
||||
|
||||
CThreadedReader::~CThreadedReader()
|
||||
{
|
||||
gracefulShutdown();
|
||||
}
|
||||
|
||||
qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
|
||||
{
|
||||
return CNetworkUtils::lastModifiedMsSinceEpoch(nwReply);
|
||||
@@ -71,11 +82,6 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
CThreadedReader::~CThreadedReader()
|
||||
{
|
||||
gracefulShutdown();
|
||||
}
|
||||
|
||||
void CThreadedReader::setInterval(int updatePeriodMs)
|
||||
{
|
||||
Q_ASSERT(this->m_updateTimer);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "blackcore/settings/reader.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/worker.h"
|
||||
|
||||
#include <QDateTime>
|
||||
@@ -32,6 +33,9 @@ namespace BlackCore
|
||||
class BLACKCORE_EXPORT CThreadedReader : public BlackMisc::CContinuousWorker
|
||||
{
|
||||
public:
|
||||
//! Log categories
|
||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Destructor
|
||||
virtual ~CThreadedReader();
|
||||
|
||||
|
||||
@@ -101,9 +101,9 @@ namespace BlackMisc
|
||||
const QString &CDataCache::persistentStore()
|
||||
{
|
||||
static const QString dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
||||
"/org.swift-project/" +
|
||||
CDirectoryUtils::normalizedApplicationDirectory() +
|
||||
"/data/cache/core";
|
||||
"/org.swift-project/" +
|
||||
CDirectoryUtils::normalizedApplicationDirectory() +
|
||||
"/data/cache/core";
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -127,10 +127,12 @@ namespace BlackMisc
|
||||
if (future.valid())
|
||||
{
|
||||
std::future_status s {};
|
||||
do { s = future.wait_for(timeout); } while (s != ready && m_revision.isNewerValueAvailable(key, getTimestampSync(key)));
|
||||
do { s = future.wait_for(timeout); }
|
||||
while (s != ready && m_revision.isNewerValueAvailable(key, getTimestampSync(key)));
|
||||
if (s != ready) { s = future.wait_for(zero); }
|
||||
if (s != ready) { return false; }
|
||||
try { future.get(); } catch (const std::future_error &) { return false; } // broken promise
|
||||
try { future.get(); }
|
||||
catch (const std::future_error &) { return false; } // broken promise
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -175,12 +177,12 @@ namespace BlackMisc
|
||||
case QLockFile::PermissionError: return "Insufficient permission";
|
||||
case QLockFile::UnknownError: return "Unknown filesystem error";
|
||||
case QLockFile::LockFailedError:
|
||||
{
|
||||
QString hostname, appname;
|
||||
qint64 pid = 0;
|
||||
lock.getLockInfo(&pid, &hostname, &appname);
|
||||
return QString("Lock open in another process (%1 %2 on %3)").arg(hostname, QString::number(pid), appname);
|
||||
}
|
||||
{
|
||||
QString hostname, appname;
|
||||
qint64 pid = 0;
|
||||
lock.getLockInfo(&pid, &hostname, &appname);
|
||||
return QString("Lock open in another process (%1 %2 on %3)").arg(hostname, QString::number(pid), appname);
|
||||
}
|
||||
default: return "Bad error number";
|
||||
}
|
||||
}
|
||||
@@ -250,6 +252,12 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
const CLogCategoryList &CDataCacheSerializer::getLogCategories()
|
||||
{
|
||||
static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::cache() };
|
||||
return cats;
|
||||
}
|
||||
|
||||
CDataCacheSerializer::CDataCacheSerializer(CDataCache *owner, const QString &revisionFileName) :
|
||||
CContinuousWorker(owner),
|
||||
m_cache(owner),
|
||||
@@ -489,7 +497,7 @@ namespace BlackMisc
|
||||
// don't try to split the conditional into multiple statements.
|
||||
// If a future is still waiting for the next update to begin, we don't want to break its associated promise.
|
||||
return (m_updateInProgress || m_pendingWrite || beginUpdate({{ key, timestamp }}, false).keepPromises())
|
||||
&& (m_timestamps.contains(key) || m_admittedQueue.contains(key));
|
||||
&&(m_timestamps.contains(key) || m_admittedQueue.contains(key));
|
||||
}
|
||||
|
||||
std::future<void> CDataCacheRevision::promiseLoadedValue(const QString &key, qint64 currentTimestamp)
|
||||
@@ -571,7 +579,7 @@ namespace BlackMisc
|
||||
timestamps.insert(key, timestamp);
|
||||
json.insert("timestamps", timestamps);
|
||||
|
||||
if (! (revisionFile.seek(0) && revisionFile.resize(0) && revisionFile.write(QJsonDocument(json).toJson()) && revisionFile.checkedClose()))
|
||||
if (!(revisionFile.seek(0) && revisionFile.resize(0) && revisionFile.write(QJsonDocument(json).toJson()) && revisionFile.checkedClose()))
|
||||
{
|
||||
CLogMessage(this).error("Failed to write to %1: %2") << revisionFile.fileName() << revisionFile.errorString();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "blackmisc/identifier.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/valuecache.h"
|
||||
#include "blackmisc/valuecacheprivate.h"
|
||||
#include "blackmisc/variant.h"
|
||||
@@ -186,6 +187,9 @@ namespace BlackMisc
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Log categories
|
||||
static const CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Constructor.
|
||||
CDataCacheSerializer(CDataCache *owner, const QString &revisionFileName);
|
||||
|
||||
|
||||
@@ -117,6 +117,20 @@ namespace BlackMisc
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! Cache
|
||||
static const CLogCategory &cache()
|
||||
{
|
||||
static const CLogCategory cat { "swift.cache" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! Background task
|
||||
static const CLogCategory &worker()
|
||||
{
|
||||
static const CLogCategory cat { "swift.worker" };
|
||||
return cat;
|
||||
}
|
||||
|
||||
//! Startup of application
|
||||
static const CLogCategory &startup()
|
||||
{
|
||||
@@ -145,6 +159,7 @@ namespace BlackMisc
|
||||
static const QList<CLogCategory> cats
|
||||
{
|
||||
uncategorized(),
|
||||
cache(),
|
||||
context(),
|
||||
contextSlot(),
|
||||
download(),
|
||||
@@ -158,7 +173,8 @@ namespace BlackMisc
|
||||
validation(),
|
||||
vatsimSpecific(),
|
||||
verification(),
|
||||
webservice()
|
||||
webservice(),
|
||||
worker()
|
||||
};
|
||||
return cats;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ namespace BlackMisc
|
||||
{ "validation", exactMatch(CLogCategory::validation()) },
|
||||
{ "verification", exactMatch(CLogCategory::verification()) },
|
||||
{ "services", exactMatch(CLogCategory::services()) },
|
||||
{ "settings", exactMatch(CLogCategory::settings()) },
|
||||
{ "cache", exactMatch(CLogCategory::cache()) },
|
||||
{ "background task", exactMatch(CLogCategory::worker()) },
|
||||
{ "model mapping", exactMatch(CLogCategory::mapping()) },
|
||||
{ "model matching", exactMatch(CLogCategory::matching()) },
|
||||
{ "swift contexts", exactMatch(CLogCategory::context()) },
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
CWorker *CWorker::fromTaskImpl(QObject *owner, const QString &name, int typeId, std::function<CVariant()> task)
|
||||
{
|
||||
auto *thread = new CRegularThread(owner);
|
||||
@@ -46,6 +45,12 @@ namespace BlackMisc
|
||||
QMetaObject::invokeMethod(this, "deleteLater");
|
||||
}
|
||||
|
||||
const CLogCategoryList &CWorkerBase::getLogCategories()
|
||||
{
|
||||
static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::worker() };
|
||||
return cats;
|
||||
}
|
||||
|
||||
void CWorkerBase::waitForFinished() noexcept
|
||||
{
|
||||
std::promise<void> promise;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKMISC_WORKER_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/invoke.h"
|
||||
#include "blackmisc/stacktrace.h"
|
||||
#include "blackmisc/variant.h"
|
||||
@@ -110,6 +111,9 @@ namespace BlackMisc
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Log categories
|
||||
static const CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Connects to a functor or method which will be called when the task is finished.
|
||||
//! \threadsafe
|
||||
template <typename T, typename F>
|
||||
|
||||
Reference in New Issue
Block a user