Set syslog severity level (#23377)

This commit is contained in:
SteWers 2025-05-06 10:37:20 +02:00 committed by GitHub
parent 38802ab5b7
commit c148c8e84d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 12 deletions

View File

@ -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 - <PRI>HOSTNAME TAG: MSG
<PRI> = Facility 16 (= local use 0), Severity 6 (= informational) => 16 * 8 + 6 = <134>
<PRI> = 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<void(const char*, uint32_t)> println) {

View File

@ -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++;
}

View File

@ -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);