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