Added autosave to loghistory
This commit is contained in:
parent
a19d27203f
commit
feb2d92e38
@ -105,9 +105,10 @@ void DownloadManager::Update()
|
||||
DownloadNext();
|
||||
}
|
||||
|
||||
// Check every second, non-blocking
|
||||
// Update every 1-2 seconds, non-blocking, the download progresses
|
||||
if ((time(0) - lastProgressCheck > 2) && (cachedNumActiveDownloads > 0))
|
||||
{
|
||||
// Mutex gets reset in Save();
|
||||
UpdateDownloadProgressPercentages();
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,7 @@ void Framework::Run()
|
||||
{
|
||||
while (XGControl::keepServerRunning)
|
||||
{
|
||||
httpServer->Update();
|
||||
DownloadManager::Update();
|
||||
Update();
|
||||
}
|
||||
|
||||
OnExit();
|
||||
@ -74,6 +73,15 @@ void Framework::PostInit()
|
||||
return;
|
||||
}
|
||||
|
||||
void Framework::Update()
|
||||
{
|
||||
httpServer->Update();
|
||||
DownloadManager::Update();
|
||||
LogHistory::Update();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Framework::OnExit()
|
||||
{
|
||||
httpServer->OnExit();
|
||||
@ -86,9 +94,9 @@ void Framework::PostExit()
|
||||
{
|
||||
XGConfig::PostExit();
|
||||
RestQueryHandler::PostExit();
|
||||
LogHistory::PostExit();
|
||||
DownloadManager::PostExit();
|
||||
ConsoleManager::PostExit();
|
||||
LogHistory::PostExit();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -15,9 +15,10 @@ public:
|
||||
void Run();
|
||||
|
||||
private:
|
||||
void PostInit();
|
||||
void OnExit();
|
||||
void PreInit();
|
||||
void PostInit();
|
||||
void Update();
|
||||
void OnExit();
|
||||
void PostExit();
|
||||
|
||||
Rest::HttpServer* httpServer;
|
||||
|
@ -5,6 +5,8 @@ using namespace Logging;
|
||||
void LogHistory::PreInit()
|
||||
{
|
||||
history = new std::vector<LogEntry*>();
|
||||
lastSave = time(0);
|
||||
didHistoryChangeSinceLastSave = false;
|
||||
|
||||
return;
|
||||
}
|
||||
@ -26,6 +28,17 @@ void LogHistory::PostExit()
|
||||
return;
|
||||
}
|
||||
|
||||
void LogHistory::Update()
|
||||
{
|
||||
if ((time(0) - lastSave > XGConfig::logging.autosave_interval) && (didHistoryChangeSinceLastSave))
|
||||
{
|
||||
// Mutex gets reset in Save();
|
||||
Save();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void LogHistory::Save()
|
||||
{
|
||||
std::stringstream textfile;
|
||||
@ -46,17 +59,23 @@ void LogHistory::Save()
|
||||
ofs << jsonFile.Render();
|
||||
ofs.close();
|
||||
|
||||
lastSave = time(0);
|
||||
didHistoryChangeSinceLastSave = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void LogHistory::AddLogToHistory(LogEntry* newEntry)
|
||||
{
|
||||
history->push_back(newEntry);
|
||||
didHistoryChangeSinceLastSave = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<LogEntry*>* LogHistory::history;
|
||||
time_t LogHistory::lastSave;
|
||||
bool LogHistory::didHistoryChangeSinceLastSave;
|
||||
|
||||
JasonPP::JsonBlock LogEntry::GetAsJson()
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ namespace Logging
|
||||
public:
|
||||
static void PreInit();
|
||||
static void PostExit();
|
||||
static void Update();
|
||||
|
||||
static void Save();
|
||||
|
||||
@ -38,6 +39,8 @@ namespace Logging
|
||||
static void AddLogToHistory(LogEntry* newEntry);
|
||||
|
||||
static std::vector<LogEntry*>* history;
|
||||
static time_t lastSave;
|
||||
static bool didHistoryChangeSinceLastSave;
|
||||
|
||||
friend Logger;
|
||||
};
|
||||
|
@ -38,6 +38,7 @@ void XGConfig::InitializeDefaultValues()
|
||||
|
||||
logging.logfile_text = "log.txt";
|
||||
logging.logfile_json = "log.json";
|
||||
logging.autosave_interval = 60 * 30; // 30 mins
|
||||
|
||||
downloader.cachedir = "dlcache";
|
||||
downloader.max_dlrate_per_thread = "100M";
|
||||
@ -65,6 +66,11 @@ void XGConfig::LoadFromJson(const JasonPP::JsonBlock& json)
|
||||
logging.logfile_text = json.ShorthandGet("logging.logfile_text").AsString;
|
||||
}
|
||||
|
||||
if (IsJsonFieldValid(json, "logging.autosave_interval", JDType::INT))
|
||||
{
|
||||
logging.autosave_interval = json.ShorthandGet("logging.autosave_interval").AsInt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (IsJsonFieldValid(json, "httpServer.port", JDType::STRING))
|
||||
@ -132,7 +138,8 @@ JsonBlock XGConfig::CreateJson()
|
||||
})),
|
||||
Ele("logging", JsonBlock({
|
||||
Ele("logfile_text", logging.logfile_text),
|
||||
Ele("logfile_json", logging.logfile_json)
|
||||
Ele("logfile_json", logging.logfile_json),
|
||||
Ele("autosave_interval", logging.autosave_interval)
|
||||
})),
|
||||
Ele("downloader", JsonBlock({
|
||||
Ele("cachedir", downloader.cachedir),
|
||||
|
@ -19,6 +19,7 @@ public:
|
||||
{
|
||||
std::string logfile_text;
|
||||
std::string logfile_json;
|
||||
int autosave_interval;
|
||||
};
|
||||
struct Downloader
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user