From c148c8e84d79e0fd9c56dfef58bf90dc191a2c71 Mon Sep 17 00:00:00 2001 From: SteWers <42718143+SteWers@users.noreply.github.com> Date: Tue, 6 May 2025 10:37:20 +0200 Subject: [PATCH] Set syslog severity level (#23377) --- tasmota/tasmota_support/support.ino | 24 ++++++++++++------- .../tasmota_xdrv_driver/xdrv_79_esp32_ble.ino | 4 ++-- .../xsns_62_esp32_mi_ble.ino | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index 4f9e151ed..f5a72ad7f 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -2437,7 +2437,7 @@ void SyslogAsync(bool refresh) { char* line; size_t len; - while (GetLog(TasmotaGlobal.syslog_level, &index, &line, &len)) { + while (int loglevel = GetLog(TasmotaGlobal.syslog_level, &index, &line, &len)) { // <--- mxtime ---> TAG: <---------------------- MSG ----------------------------> // 00:00:02.096-029 HTP: Web server active on wemos5 with IP address 192.168.2.172 // HTP: Web server active on wemos5 with IP address 192.168.2.172 @@ -2473,12 +2473,18 @@ void SyslogAsync(bool refresh) { // snprintf_P(header, sizeof(header), PSTR("%s ESP-"), NetworkHostname()); /* Legacy format - HOSTNAME TAG: MSG - = Facility 16 (= local use 0), Severity 6 (= informational) => 16 * 8 + 6 = <134> + = Facility 16 (= local use 0), Severity 6 (= informational) => 16 * 8 + 6 = 128 + 6 = <134> SYSLOG-MSG = <134>wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172 Result = 2023-12-21T11:31:50.378816+01:00 wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172 Notice in both cases the date and time is taken from the syslog server. Uncompression message is gone. + + Translate Tasmota loglevel to syslog severity level: + LOG_LEVEL_ERROR 1 -> severity level 3 - Error + LOG_LEVEL_INFO 2 -> severity level 6 - Informational + LOG_LEVEL_DEBUG 3 -> severity level 7 - Debug + LOG_LEVEL_DEBUG_MORE 4 -> severity level 7 - Debug */ - snprintf_P(header, sizeof(header), PSTR("<134>%s ESP-"), NetworkHostname()); + snprintf_P(header, sizeof(header), PSTR("<%d>%s ESP-"), 128 + min(loglevel * 3, 7), NetworkHostname()); // SYSLOG-MSG = <134>wemos5 Tasmota HTP: Web server active on wemos5 with IP address 192.168.2.172 // Result = 2023-12-21T11:31:50.378816+01:00 wemos5 Tasmota HTP: Web server active on wemos5 with IP address 192.168.2.172 @@ -2562,12 +2568,12 @@ bool NeedLogRefresh(uint32_t req_loglevel, uint32_t index) { return ((line - TasmotaGlobal.log_buffer) < LOG_BUFFER_SIZE / 4); } -bool GetLog(uint32_t req_loglevel, uint32_t* index_p, char** entry_pp, size_t* len_p) { - if (!TasmotaGlobal.log_buffer) { return false; } // Leave now if there is no buffer available - if (TasmotaGlobal.uptime < 3) { return false; } // Allow time to setup correct log level +uint32_t GetLog(uint32_t req_loglevel, uint32_t* index_p, char** entry_pp, size_t* len_p) { + if (!TasmotaGlobal.log_buffer) { return 0; } // Leave now if there is no buffer available + if (TasmotaGlobal.uptime < 3) { return 0; } // Allow time to setup correct log level uint32_t index = *index_p; - if (!req_loglevel || (index == TasmotaGlobal.log_buffer_pointer)) { return false; } + if (!req_loglevel || (index == TasmotaGlobal.log_buffer_pointer)) { return 0; } #ifdef ESP32 // this takes the mutex, and will be release when the class is destroyed - @@ -2604,11 +2610,11 @@ bool GetLog(uint32_t req_loglevel, uint32_t* index_p, char** entry_pp, size_t* l (TasmotaGlobal.masterlog_level <= req_loglevel)) { *entry_pp = entry_p; *len_p = len; - return true; + return loglevel; } delay(0); } while (index != TasmotaGlobal.log_buffer_pointer); - return false; + return 0; } bool LogDataJsonPrettyPrint(const char *log_line, uint32_t log_data_len, std::function println) { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino b/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino index f9bb63a3a..4fd0c8211 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_79_esp32_ble.ino @@ -2479,7 +2479,7 @@ int extQueueOperation(BLE_ESP32::generic_sensor_t** op){ } if (!BLEMasterEnable){ - AddLog(LOG_LEVEL_ERROR,PSTR("BLE: extQueueOperation: BLE is deiabled")); + AddLog(LOG_LEVEL_ERROR, PSTR("BLE: extQueueOperation: BLE is disabled")); return 0; } @@ -2981,7 +2981,7 @@ void CmndBLEAlias(void){ return; } - AddLog(LOG_LEVEL_ERROR,PSTR("BLE: Add Alias mac %s = name %s"), mac, p); + AddLog(LOG_LEVEL_INFO, PSTR("BLE: Add Alias mac %s = name %s"), mac, p); if (addAlias( addr, name )){ added++; } diff --git a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino index 1a94f765f..7690af927 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi_ble.ino @@ -2711,7 +2711,7 @@ void CmndMi32Keys(void){ return; } - AddLog(LOG_LEVEL_ERROR,PSTR("M32: Add key mac %s = key %s"), mac, key); + AddLog(LOG_LEVEL_INFO, PSTR("M32: Add key mac %s = key %s"), mac, key); char tmp[20]; // convert mac back to string ToHex_P(addr,6,tmp,20,0);