diff --git a/libs/http_server/microhttpd_server_p.cpp b/libs/http_server/microhttpd_server_p.cpp index 1bc270ea..06c3d0ee 100644 --- a/libs/http_server/microhttpd_server_p.cpp +++ b/libs/http_server/microhttpd_server_p.cpp @@ -188,7 +188,7 @@ int answer_to_connection(void * cls, return MHD_NO; } - piCout << "answer" << url << method << (int)m << server; + // piCout << "answer" << url << method << (int)m << server; MicrohttpdServerConnection *& conn((MicrohttpdServerConnection *&)(*con_cls)); if (!conn) { conn = new MicrohttpdServerConnection(); diff --git a/libs/main/application/pilog.cpp b/libs/main/application/pilog.cpp index 4daba584..e6adc2ec 100644 --- a/libs/main/application/pilog.cpp +++ b/libs/main/application/pilog.cpp @@ -110,6 +110,58 @@ void PILog::stop() { } +PIStringList PILog::readAllLogs() const { + PIMap 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; diff --git a/libs/main/application/pilog.h b/libs/main/application/pilog.h index ceb6c60c..64fe8ad5 100644 --- a/libs/main/application/pilog.h +++ b/libs/main/application/pilog.h @@ -144,6 +144,10 @@ public: //! \~russian Записывает все строки из очереди и останавливается. Также вызывается в деструкторе. void stop(); + //! \~english Read all previous and current log content and returns them as %PIStringList. + //! \~russian Читает все предыдущие и текущий логи и возвращает их как %PIStringList. + PIStringList readAllLogs() const; + private: EVENT_HANDLER2(void, coutDone, int, id, PIString *, buff); @@ -160,8 +164,8 @@ private: void newFile(); void run() override; - PIMutex log_mutex; - PIFile log_file; + mutable PIMutex log_mutex; + mutable PIFile log_file; PIIOTextStream log_ts; PITimeMeasurer split_tm; PISystemTime split_time;