Log streaming over websocket activated
This commit is contained in:
parent
149fb4fb03
commit
21ce6d5870
|
@ -64,6 +64,7 @@ public:
|
|||
}
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static Logger *getInstance();
|
||||
|
@ -107,6 +108,6 @@ private:
|
|||
Logger();
|
||||
|
||||
char *data_;
|
||||
size_t totalSize_;
|
||||
size_t currentSize_;
|
||||
size_t totalSize_ = 0;
|
||||
size_t currentSize_ = 0;
|
||||
};
|
||||
|
|
|
@ -43,3 +43,4 @@ test_ignore = test_embedded
|
|||
build_flags = -g -DPLATFORM_NATIVE -std=c++17 -O0
|
||||
build_src_filter = +<*> -<firmware_main.cpp> -<WifiManager.cpp> -<WifiAPI.cpp>
|
||||
lib_compat_mode = off
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ class LoggingAPI
|
|||
switch(code) {
|
||||
case MessageCode::LOG_STREAMING_START:
|
||||
running_ = true;
|
||||
if(firstCall_) {
|
||||
const Logger * logger = Logger::getInstance();
|
||||
lastEnd_ = logger->begin();
|
||||
firstCall_ = false;
|
||||
}
|
||||
return true;
|
||||
case MessageCode::LOG_STREAMING_STOP:
|
||||
running_ = false;
|
||||
|
@ -28,27 +33,25 @@ class LoggingAPI
|
|||
template <typename TServer>
|
||||
void iteration(TServer &server)
|
||||
{
|
||||
const Logger * logger = Logger::getInstance();
|
||||
|
||||
if(running_)
|
||||
{
|
||||
StaticJsonDocument<1024> data;
|
||||
for (int i = 0; i < MAX_WEBSOCKET_CONNECTIONS; ++i)
|
||||
{
|
||||
auto &c = server.client(i);
|
||||
if (c.available())
|
||||
{
|
||||
const Logger * logger = Logger::getInstance();
|
||||
const auto beginIt = lastEnd_;
|
||||
const auto endIt = logger->end();
|
||||
|
||||
}
|
||||
StaticJsonDocument<512> data;
|
||||
for(auto it = beginIt; it != endIt; ++beginIt) {
|
||||
data["time"] = it.time_millis();
|
||||
data["msg"] = it.message();
|
||||
server.template sendToAll<512>(MessageCode::LOG_UPDATE, data);
|
||||
}
|
||||
lastEnd_ = endIt;
|
||||
}
|
||||
|
||||
|
||||
lastOffset_ = logger->currentSize();
|
||||
}
|
||||
|
||||
private:
|
||||
bool running_ = false;
|
||||
size_t lastOffset_ = 0;
|
||||
Logger::iterator lastEnd_;
|
||||
bool firstCall_ = false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue