diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c
index 25f748ffd..e6b004cc0 100644
--- a/src/httpserver/http_fns.c
+++ b/src/httpserver/http_fns.c
@@ -1280,6 +1280,9 @@ const char *CMD_GetResultString(commandResult_t r) {
return "Bad argument";
return "Unknown error";
}
+// all log printfs made by command will be sent also to request
+void LOG_SetCommandHTTPRedirectReply(http_request_t* request);
+
int http_fn_cmd_tool(http_request_t* request) {
commandResult_t res;
const char *resStr;
@@ -1290,9 +1293,14 @@ int http_fn_cmd_tool(http_request_t* request) {
poststr(request, "
Command Tool
");
poststr(request, "This is a basic command line.
");
poststr(request, "Please consider using 'Web Application' console with more options and real time log view.
");
+ poststr(request, "Remember that some commands are added after a restart when a driver is activated...
");
if (http_getArg(request->url, "cmd", tmpA, sizeof(tmpA))) {
+ poststr(request, "
");
+ // all log printfs made by command will be sent also to request
+ LOG_SetCommandHTTPRedirectReply(request);
res = CMD_ExecuteCommand(tmpA, COMMAND_FLAG_SOURCE_CONSOLE);
+ LOG_SetCommandHTTPRedirectReply(0);
resStr = CMD_GetResultString(res);
hprintf255(request, "%s
", resStr);
poststr(request, "
");
diff --git a/src/logging/logging.c b/src/logging/logging.c
index 43cfd5aac..6a67be17e 100644
--- a/src/logging/logging.c
+++ b/src/logging/logging.c
@@ -298,7 +298,13 @@ static void inittcplog(){
startLogServer();
tcpLogStarted = 1;
}
+http_request_t *g_log_alsoPrintToHTTP = 0;
+bool b_guard_recursivePrint = false;
+// all log printfs made by command will be sent also to request
+void LOG_SetCommandHTTPRedirectReply(http_request_t* request) {
+ g_log_alsoPrintToHTTP = request;
+}
// adds a log to the log memory
// if head collides with either tail, move the tails on.
void addLogAdv(int level, int feature, const char* fmt, ...)
@@ -373,6 +379,16 @@ void addLogAdv(int level, int feature, const char* fmt, ...)
//#if PLATFORM_BL602
//printf(tmp);
//#endif
+ // This is used by HTTP console
+ if (g_log_alsoPrintToHTTP) {
+ // guard here is used for the rare case when poststr attempts to do an addLogAdv as well
+ if (b_guard_recursivePrint == false) {
+ b_guard_recursivePrint = true;
+ poststr(g_log_alsoPrintToHTTP, tmp);
+ poststr(g_log_alsoPrintToHTTP, "
");
+ b_guard_recursivePrint = false;
+ }
+ }
if (g_extraSocketToSendLOG)
{
send(g_extraSocketToSendLOG, tmp, strlen(tmp), 0);