new method PILog::readAllLogs
This commit is contained in:
@@ -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) {
|
||||
if (!buffer) return;
|
||||
if (!id_by_cat.containsValue(id)) return;
|
||||
|
||||
Reference in New Issue
Block a user