From 2eb4eef08c5003fcb2e181b4f938c549b3e80118 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 18 Dec 2020 16:30:37 +0100 Subject: [PATCH] Rename web_log to log_buffer --- tasmota/support.ino | 52 +++++++++++++++++------------------ tasmota/tasmota.ino | 4 +-- tasmota/tasmota_globals.h | 6 +--- tasmota/xdrv_01_webserver.ino | 14 +++++----- tasmota/xdrv_02_mqtt.ino | 4 +-- tasmota/xdrv_40_telegram.ino | 6 ++-- 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index b1d30b41d..2905adb6e 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1909,14 +1909,14 @@ void Syslog(void) WiFi.hostByName(SettingsText(SET_SYSLOG_HOST), syslog_host_addr); // If sleep enabled this might result in exception so try to do it once using hash } if (PortUdp.beginPacket(syslog_host_addr, Settings.syslog_port)) { - char syslog_preamble[64]; // Hostname + Id + char syslog_preamble[64]; // Hostname + Id snprintf_P(syslog_preamble, sizeof(syslog_preamble), PSTR("%s ESP-"), NetworkHostname()); memmove(TasmotaGlobal.log_data + strlen(syslog_preamble), TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data) - strlen(syslog_preamble)); TasmotaGlobal.log_data[sizeof(TasmotaGlobal.log_data) -1] = '\0'; memcpy(TasmotaGlobal.log_data, syslog_preamble, strlen(syslog_preamble)); PortUdp_write(TasmotaGlobal.log_data, strlen(TasmotaGlobal.log_data)); PortUdp.endPacket(); - delay(1); // Add time for UDP handling (#5512) + delay(1); // Add time for UDP handling (#5512) } else { TasmotaGlobal.syslog_level = 0; TasmotaGlobal.syslog_timer = SYSLOG_TIMER; @@ -1928,7 +1928,7 @@ void SyslogAsync(void) { static uint32_t counter = 1; if (!TasmotaGlobal.syslog_level || - (counter == TasmotaGlobal.web_log_index) || + (counter == TasmotaGlobal.log_buffer_pointer) || TasmotaGlobal.global_state.network_down) { return; } do { @@ -1943,8 +1943,8 @@ void SyslogAsync(void) { } counter++; counter &= 0xFF; - if (!counter) { counter++; } // Skip 0 as it is not allowed - } while (counter != TasmotaGlobal.web_log_index); + if (!counter) { counter++; } // Skip 0 as it is not allowed + } while (counter != TasmotaGlobal.log_buffer_pointer); } uint32_t GetLog(uint32_t idx, char** entry_pp, size_t* len_p) { @@ -1952,21 +1952,21 @@ uint32_t GetLog(uint32_t idx, char** entry_pp, size_t* len_p) { size_t len = 0; uint32_t loglevel = 0; if (idx) { - char* it = TasmotaGlobal.web_log; + char* it = TasmotaGlobal.log_buffer; do { uint32_t cur_idx = *it; it++; size_t tmp = strchrspn(it, '\1'); - tmp++; // Skip terminating '\1' - if (cur_idx == idx) { // Found the requested entry + tmp++; // Skip terminating '\1' + if (cur_idx == idx) { // Found the requested entry loglevel = *it - '0'; - it++; // Skip loglevel + it++; // Skip loglevel len = tmp -1; entry_p = it; break; } it += tmp; - } while (it < TasmotaGlobal.web_log + WEB_LOG_SIZE && *it != '\0'); + } while (it < TasmotaGlobal.log_buffer + LOG_BUFFER_SIZE && *it != '\0'); } *entry_pp = entry_p; *len_p = len; @@ -1988,28 +1988,28 @@ void AddLog(uint32_t loglevel) { uint32_t highest_loglevel = Settings.weblog_level; if (Settings.mqttlog_level > highest_loglevel) { highest_loglevel = Settings.mqttlog_level; } if (TasmotaGlobal.syslog_level > highest_loglevel) { highest_loglevel = TasmotaGlobal.syslog_level; } - if ((loglevel <= highest_loglevel) && // Log only when needed + if ((loglevel <= highest_loglevel) && // Log only when needed (TasmotaGlobal.masterlog_level <= highest_loglevel)) { // Delimited, zero-terminated buffer of log lines. // Each entry has this format: [index][loglevel][log data]['\1'] - TasmotaGlobal.web_log_index &= 0xFF; - if (!TasmotaGlobal.web_log_index) { - TasmotaGlobal.web_log_index++; // Index 0 is not allowed as it is the end of char string + TasmotaGlobal.log_buffer_pointer &= 0xFF; + if (!TasmotaGlobal.log_buffer_pointer) { + TasmotaGlobal.log_buffer_pointer++; // Index 0 is not allowed as it is the end of char string } - while (TasmotaGlobal.web_log_index == TasmotaGlobal.web_log[0] || // If log already holds the next index, remove it - strlen(TasmotaGlobal.web_log) + strlen(TasmotaGlobal.log_data) + strlen(mxtime) + 4 > WEB_LOG_SIZE) // 4 = web_log_index + '\1' + '\0' + while (TasmotaGlobal.log_buffer_pointer == TasmotaGlobal.log_buffer[0] || // If log already holds the next index, remove it + strlen(TasmotaGlobal.log_buffer) + strlen(TasmotaGlobal.log_data) + strlen(mxtime) + 4 > LOG_BUFFER_SIZE) // 4 = log_buffer_pointer + '\1' + '\0' { - char* it = TasmotaGlobal.web_log; - it++; // Skip web_log_index - it += strchrspn(it, '\1'); // Skip log line - it++; // Skip delimiting "\1" - memmove(TasmotaGlobal.web_log, it, WEB_LOG_SIZE -(it-TasmotaGlobal.web_log)); // Move buffer forward to remove oldest log line + char* it = TasmotaGlobal.log_buffer; + it++; // Skip log_buffer_pointer + it += strchrspn(it, '\1'); // Skip log line + it++; // Skip delimiting "\1" + memmove(TasmotaGlobal.log_buffer, it, LOG_BUFFER_SIZE -(it-TasmotaGlobal.log_buffer)); // Move buffer forward to remove oldest log line } - snprintf_P(TasmotaGlobal.web_log, sizeof(TasmotaGlobal.web_log), PSTR("%s%c%c%s%s\1"), - TasmotaGlobal.web_log, TasmotaGlobal.web_log_index++, '0'+loglevel, mxtime, TasmotaGlobal.log_data); - TasmotaGlobal.web_log_index &= 0xFF; - if (!TasmotaGlobal.web_log_index) { - TasmotaGlobal.web_log_index++; // Index 0 is not allowed as it is the end of char string + snprintf_P(TasmotaGlobal.log_buffer, sizeof(TasmotaGlobal.log_buffer), PSTR("%s%c%c%s%s\1"), + TasmotaGlobal.log_buffer, TasmotaGlobal.log_buffer_pointer++, '0'+loglevel, mxtime, TasmotaGlobal.log_data); + TasmotaGlobal.log_buffer_pointer &= 0xFF; + if (!TasmotaGlobal.log_buffer_pointer) { + TasmotaGlobal.log_buffer_pointer++; // Index 0 is not allowed as it is the end of char string } } TasmotaGlobal.prepped_loglevel = 0; diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index c14378a4a..6191c0f6a 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -86,7 +86,7 @@ struct { uint32_t blink_timer; // Power cycle timer uint32_t backlog_timer; // Timer for next command in backlog uint32_t loop_load_avg; // Indicative loop load average - uint32_t web_log_index; // Index in Web log buffer + uint32_t log_buffer_pointer; // Index in log buffer uint32_t uptime; // Counting every second until 4294967295 = 130 year power_t power; // Current copy of Settings.power @@ -169,7 +169,7 @@ struct { char mqtt_topic[TOPSZ]; // Composed MQTT topic char mqtt_data[MESSZ]; // MQTT publish buffer and web page ajax buffer char log_data[LOGSZ]; // Logging - char web_log[WEB_LOG_SIZE]; // Web log buffer + char log_buffer[LOG_BUFFER_SIZE]; // Web log buffer } TasmotaGlobal; #ifdef SUPPORT_IF_STATEMENT diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 3ca9923e0..14cc1532d 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -209,11 +209,7 @@ String EthernetMacAddress(void); #define WS2812_LEDS 30 // [Pixels] Number of LEDs #endif -//#ifdef USE_MQTT_TLS // Set to 4000 on 20200922 per #9305 -// const uint16_t WEB_LOG_SIZE = 2000; // Max number of characters in weblog -//#else - const uint16_t WEB_LOG_SIZE = 4000; // Max number of characters in weblog -//#endif +const uint16_t LOG_BUFFER_SIZE = 4000; // Max number of characters in logbuffer used by weblog, syslog and mqttlog #if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2) || defined(ARDUINO_ESP8266_RELEASE_2_5_0) || defined(ARDUINO_ESP8266_RELEASE_2_5_1) || defined(ARDUINO_ESP8266_RELEASE_2_5_2) #error "Arduino ESP8266 Core versions before 2.7.1 are not supported" diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 6a76439b2..012294b82 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -3017,11 +3017,11 @@ void HandleHttpCommand(void) } WSContentBegin(200, CT_JSON); - uint32_t curridx = TasmotaGlobal.web_log_index; + uint32_t curridx = TasmotaGlobal.log_buffer_pointer; String svalue = Webserver->arg("cmnd"); if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) { ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND); - if (TasmotaGlobal.web_log_index != curridx) { + if (TasmotaGlobal.log_buffer_pointer != curridx) { uint32_t counter = curridx; WSContentSend_P(PSTR("{")); bool cflg = false; @@ -3046,7 +3046,7 @@ void HandleHttpCommand(void) counter++; counter &= 0xFF; if (!counter) counter++; // Skip 0 as it is not allowed - } while (counter != TasmotaGlobal.web_log_index); + } while (counter != TasmotaGlobal.log_buffer_pointer); WSContentSend_P(PSTR("}")); } else { WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENABLE_WEBLOG_FOR_RESPONSE "\"}")); @@ -3094,14 +3094,14 @@ void HandleConsoleRefresh(void) if (strlen(stmp)) { counter = atoi(stmp); } WSContentBegin(200, CT_PLAIN); - WSContentSend_P(PSTR("%d}1%d}1"), TasmotaGlobal.web_log_index, Web.reset_web_log_flag); + WSContentSend_P(PSTR("%d}1%d}1"), TasmotaGlobal.log_buffer_pointer, Web.reset_web_log_flag); if (!Web.reset_web_log_flag) { counter = 0; Web.reset_web_log_flag = true; } - if (counter != TasmotaGlobal.web_log_index) { + if (counter != TasmotaGlobal.log_buffer_pointer) { if (!counter) { - counter = TasmotaGlobal.web_log_index; + counter = TasmotaGlobal.log_buffer_pointer; cflg = false; } do { @@ -3120,7 +3120,7 @@ void HandleConsoleRefresh(void) counter++; counter &= 0xFF; if (!counter) { counter++; } // Skip log index 0 as it is not allowed - } while (counter != TasmotaGlobal.web_log_index); + } while (counter != TasmotaGlobal.log_buffer_pointer); } WSContentSend_P(PSTR("}1")); WSContentEnd(); diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index f1e098eb1..145d5df16 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -296,7 +296,7 @@ void MqttPublishLoggingAsync(void) { if (!Settings.flag.mqtt_enabled || // SetOption3 - Enable MQTT !Settings.mqttlog_level || - (counter == TasmotaGlobal.web_log_index) || + (counter == TasmotaGlobal.log_buffer_pointer) || TasmotaGlobal.global_state.mqtt_down) { return; } do { @@ -314,7 +314,7 @@ void MqttPublishLoggingAsync(void) { counter++; counter &= 0xFF; if (!counter) { counter++; } // Skip 0 as it is not allowed - } while (counter != TasmotaGlobal.web_log_index); + } while (counter != TasmotaGlobal.log_buffer_pointer); } void MqttPublish(const char* topic, bool retained) diff --git a/tasmota/xdrv_40_telegram.ino b/tasmota/xdrv_40_telegram.ino index a810237b5..2ce3769d5 100644 --- a/tasmota/xdrv_40_telegram.ino +++ b/tasmota/xdrv_40_telegram.ino @@ -289,9 +289,9 @@ void TelegramSendGetMe(void) { String TelegramExecuteCommand(const char *svalue) { String response = ""; - uint32_t curridx = TasmotaGlobal.web_log_index; + uint32_t curridx = TasmotaGlobal.log_buffer_pointer; ExecuteCommand(svalue, SRC_CHAT); - if (TasmotaGlobal.web_log_index != curridx) { + if (TasmotaGlobal.log_buffer_pointer != curridx) { uint32_t counter = curridx; response = F("{"); bool cflg = false; @@ -317,7 +317,7 @@ String TelegramExecuteCommand(const char *svalue) { counter++; counter &= 0xFF; if (!counter) counter++; // Skip 0 as it is not allowed - } while (counter != TasmotaGlobal.web_log_index); + } while (counter != TasmotaGlobal.log_buffer_pointer); response += F("}"); } else { response = F("{\"" D_RSLT_WARNING "\":\"" D_ENABLE_WEBLOG_FOR_RESPONSE "\"}");