new method PILog::readAllLogs
This commit is contained in:
@@ -188,7 +188,7 @@ int answer_to_connection(void * cls,
|
|||||||
return MHD_NO;
|
return MHD_NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
piCout << "answer" << url << method << (int)m << server;
|
// piCout << "answer" << url << method << (int)m << server;
|
||||||
MicrohttpdServerConnection *& conn((MicrohttpdServerConnection *&)(*con_cls));
|
MicrohttpdServerConnection *& conn((MicrohttpdServerConnection *&)(*con_cls));
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
conn = new MicrohttpdServerConnection();
|
conn = new MicrohttpdServerConnection();
|
||||||
|
|||||||
@@ -110,6 +110,58 @@ void PILog::stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIStringList PILog::readAllLogs() const {
|
||||||
|
PIMap<PISystemTime, PIString> names;
|
||||||
|
auto dir = PIDir(log_dir);
|
||||||
|
auto fil = dir.entries();
|
||||||
|
for (auto fi: fil) {
|
||||||
|
if (!fi.isFile()) continue;
|
||||||
|
if (!fi.name().contains(".log.")) continue;
|
||||||
|
names[PIDateTime::current().fromString(fi.baseName(), "yyyy_MM_dd__hh_mm_ss").toSystemTime()] = dir.relative(fi.path);
|
||||||
|
}
|
||||||
|
PIStringList ret;
|
||||||
|
PIString cur_filename = dir.relative(log_file.path());
|
||||||
|
auto it = names.makeIterator();
|
||||||
|
bool was_own = false;
|
||||||
|
auto readFile = [&ret](PIFile * f) {
|
||||||
|
PIIOTextStream ts(f);
|
||||||
|
PIString line;
|
||||||
|
while (!ts.isEnd()) {
|
||||||
|
line = ts.readLine().trim();
|
||||||
|
if (line.isNotEmpty()) ret << line;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
while (it.next()) {
|
||||||
|
PIFile * f = nullptr;
|
||||||
|
bool own = true;
|
||||||
|
if (it.value() == cur_filename) {
|
||||||
|
log_mutex.lock();
|
||||||
|
f = &log_file;
|
||||||
|
f->seekToBegin();
|
||||||
|
own = false;
|
||||||
|
was_own = true;
|
||||||
|
} else {
|
||||||
|
f = new PIFile(log_dir + "/" + it.value(), PIIODevice::ReadOnly);
|
||||||
|
}
|
||||||
|
readFile(f);
|
||||||
|
if (own)
|
||||||
|
delete f;
|
||||||
|
else {
|
||||||
|
f->seekToEnd();
|
||||||
|
log_mutex.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!was_own) {
|
||||||
|
log_mutex.lock();
|
||||||
|
log_file.seekToBegin();
|
||||||
|
readFile(&log_file);
|
||||||
|
log_file.seekToEnd();
|
||||||
|
log_mutex.unlock();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PILog::coutDone(int id, PIString * buffer) {
|
void PILog::coutDone(int id, PIString * buffer) {
|
||||||
if (!buffer) return;
|
if (!buffer) return;
|
||||||
if (!id_by_cat.containsValue(id)) return;
|
if (!id_by_cat.containsValue(id)) return;
|
||||||
|
|||||||
@@ -144,6 +144,10 @@ public:
|
|||||||
//! \~russian Записывает все строки из очереди и останавливается. Также вызывается в деструкторе.
|
//! \~russian Записывает все строки из очереди и останавливается. Также вызывается в деструкторе.
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
//! \~english Read all previous and current log content and returns them as %PIStringList.
|
||||||
|
//! \~russian Читает все предыдущие и текущий логи и возвращает их как %PIStringList.
|
||||||
|
PIStringList readAllLogs() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EVENT_HANDLER2(void, coutDone, int, id, PIString *, buff);
|
EVENT_HANDLER2(void, coutDone, int, id, PIString *, buff);
|
||||||
|
|
||||||
@@ -160,8 +164,8 @@ private:
|
|||||||
void newFile();
|
void newFile();
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
PIMutex log_mutex;
|
mutable PIMutex log_mutex;
|
||||||
PIFile log_file;
|
mutable PIFile log_file;
|
||||||
PIIOTextStream log_ts;
|
PIIOTextStream log_ts;
|
||||||
PITimeMeasurer split_tm;
|
PITimeMeasurer split_tm;
|
||||||
PISystemTime split_time;
|
PISystemTime split_time;
|
||||||
|
|||||||
Reference in New Issue
Block a user