ESPLogger
ESPLogger copied to clipboard
Serve it over HTTP
Hello, how would you serve it over HTTP? Is there an example? I don't think serving the log directly from SPIFFS into the WebServer handler function is the appropriate method mainly because there is no possibility to store "\n" or "\r".
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, ....);
});
so serving the file as text to be read from the browser would be tricky to read. I think the same applies also by using this idea with the downside that the log is flushed so my understanding is that it will be removed from SPIFFS which is not always ideal
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
logger.flush(); //set log_string via flusher handler
request->send(200, "text/text", log_string);
});
What's the reason why "\n" cannot be used in the text? Regards,
Hi,
I think that the best way to download without deleting the log from the filesystem is using streamFile(..)
:
server.sendHeader("Content-Type", "text/text");
server.sendHeader("Content-Disposition", "attachment; filename="+filename);
server.sendHeader("Connection", "close");
server.streamFile(downloadFile, "application/octet-stream");
or calling the send(..)
function that takes a general stream. This is the prototype on ESP8266:
void WebServer::send(int code, const char* content_type, Stream* stream, size_t content_length = 0);