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