Document different syslog layouts

This commit is contained in:
Theo Arends 2023-12-21 14:30:49 +01:00
parent a445c7f23a
commit 2f824b1976
2 changed files with 61 additions and 10 deletions

View File

@ -2297,7 +2297,7 @@ void SyslogAsync(bool refresh) {
char* line; char* line;
size_t len; size_t len;
while (GetLog(TasmotaGlobal.syslog_level, &index, &line, &len)) { while (GetLog(TasmotaGlobal.syslog_level, &index, &line, &len)) {
// <--- mxtime ---> TAG MSG // <--- mxtime ---> TAG: <---------------------- MSG ---------------------------->
// 00:00:02.096-029 HTP: Web server active on wemos5 with IP address 192.168.2.172 // 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 // HTP: Web server active on wemos5 with IP address 192.168.2.172
uint32_t mxtime = strchr(line, ' ') - line +1; // Remove mxtime uint32_t mxtime = strchr(line, ' ') - line +1; // Remove mxtime
@ -2322,14 +2322,55 @@ void SyslogAsync(bool refresh) {
} }
char header[64]; char header[64];
// RFC3164 - BSD syslog protocol - <PRI>TIMESTAMP HOSTNAME TAG MSG /* Legacy format (until v13.3.0.1) - HOSTNAME TAG: MSG
// <PRI> = Facility 16 (= local use 0), Severity 6 (= informational) => 16 * 8 + 6 = <134> SYSLOG-MSG = wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172
// TIMESTAMP = Mmm dd hh:mm:ss Result = 2023-12-20T13:41:11.825749+01:00 wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172
// <134>Jan 1 00:00:02 wemos5 ESP-HTP: server active on wemos5 with IP address 192.168.2.172 and below message in syslog if hostname starts with a "z"
snprintf_P(header, sizeof(header), PSTR("<134>%s %s ESP-"), GetSyslogDate(line).c_str(), NetworkHostname()); 2023-12-17T00:09:52.797782+01:00 domus8 rsyslogd: Uncompression of a message failed with return code -3 - enable debug logging if you need further information. Message ignored. [v8.2302.0]
// Legacy format Notice in both cases the date and time is taken from the syslog server
*/
// snprintf_P(header, sizeof(header), PSTR("%s ESP-"), NetworkHostname()); // 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>
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.
*/
snprintf_P(header, sizeof(header), PSTR("<134>%s ESP-"), NetworkHostname());
// Result = 2023-12-21T11:31:50.378816+01:00 wemos5 Tasmota HTP: Web server active on wemos5 with IP address 192.168.2.172
// snprintf_P(header, sizeof(header), PSTR("<134>%s Tasmota "), NetworkHostname());
/* RFC3164 - BSD syslog protocol - <PRI>TIMESTAMP HOSTNAME TAG: MSG
<PRI> = Facility 16 (= local use 0), Severity 6 (= informational) => 16 * 8 + 6 = <134>
TIMESTAMP = Mmm dd hh:mm:ss
SYSLOG-MSG = <134>Jan 1 00:00:02 wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172
Result = 2023-01-01T00:00:02+01:00 wemos5 ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172
Notice Year is taken from syslog server. Month, day and time is provided by Tasmota device. No milliseconds
*/
// snprintf_P(header, sizeof(header), PSTR("<134>%s %s ESP-"), GetSyslogDate(line).c_str(), NetworkHostname());
// Result = 2023-01-01T00:00:02+01:00 wemos5 Tasmota HTP: Web server active on wemos5 with IP address 192.168.2.172
// snprintf_P(header, sizeof(header), PSTR("<134>%s %s Tasmota "), GetSyslogDate(line).c_str(), NetworkHostname());
/* RFC5425 - Syslog protocol - <PRI>VERSION TIMESTAMP HOSTNAME APP_NAME PROCID STRUCTURED-DATA MSGID MSG
<PRI> = Facility 16 (= local use 0), Severity 6 (= informational) => 16 * 8 + 6 = <134>
TIMESTAMP = yyyy-mm-ddThh:mm:ss.nnnZ (= UTC) or yyyy-mm-ddThh:mm:ss.nnn-hh:mm (= local with timezone)
APP_NAME = Tasmota
PROCID = -
STRUCTURED-DATA = -
MSGID = -
SYSLOG-MSG = <134>1 2023-01-01T00:00:02.096000+01:00 wemos5 Tasmota - - HTP: Web server active on wemos5 with IP address 192.168.2.172
Result = 1970-01-01T00:00:02.096000+00:00 wemos5 Tasmota ESP-HTP: Web server active on wemos5 with IP address 192.168.2.172
Notice date and time is provided by Tasmota device.
*/
// char line_time[13];
// subStr(line_time, line, " ", 1); // 00:00:02.096-026
// subStr(line_time, line_time, "-", 1); // 00:00:02.096
// String systime = GetDate() + line_time + "000" + GetTimeZone(); // 1970-01-01T00:00:02.096000+01:00
// snprintf_P(header, sizeof(header), PSTR("<134>1 %s %s Tasmota - - ESP-"), systime.c_str(), NetworkHostname());
// Result = 1970-01-01T00:00:02.096000+00:00 wemos5 Tasmota HTP: Web server active on wemos5 with IP address 192.168.2.172
// snprintf_P(header, sizeof(header), PSTR("<134>1 %s %s Tasmota - - "), systime.c_str(), NetworkHostname());
char* line_start = line +mxtime; char* line_start = line +mxtime;
#ifdef ESP8266 #ifdef ESP8266
// Packets over 1460 bytes are not send // Packets over 1460 bytes are not send

View File

@ -121,6 +121,13 @@ String GetSyslogDate(char* mxtime) {
return String(dt); return String(dt);
} }
String GetDate(void) {
// yyyy-mm-ddT
char dt[12];
snprintf_P(dt, sizeof(dt), PSTR("%04d-%02d-%02dT"), RtcTime.year, RtcTime.month, RtcTime.day_of_month);
return String(dt);
}
String GetMinuteTime(uint32_t minutes) { String GetMinuteTime(uint32_t minutes) {
char tm[6]; char tm[6];
snprintf_P(tm, sizeof(tm), PSTR("%02d:%02d"), minutes / 60, minutes % 60); snprintf_P(tm, sizeof(tm), PSTR("%02d:%02d"), minutes / 60, minutes % 60);
@ -207,14 +214,17 @@ String GetDateAndTime(uint8_t time_type) {
if (DT_LOCAL_MILLIS == time_type) { if (DT_LOCAL_MILLIS == time_type) {
char ms[10]; char ms[10];
snprintf_P(ms, sizeof(ms), PSTR(".%03d"), RtcMillis()); snprintf_P(ms, sizeof(ms), PSTR(".%03d"), RtcMillis());
dt += ms; dt += ms; // 2017-03-07T11:08:02.123
time_type = DT_LOCAL; time_type = DT_LOCAL;
} }
if (Settings->flag3.time_append_timezone && (DT_LOCAL == time_type)) { // SetOption52 - Append timezone to JSON time if (DT_UTC == time_type) {
dt += "Z"; // 2017-03-07T11:08:02.123Z
}
else if (Settings->flag3.time_append_timezone && (DT_LOCAL == time_type)) { // SetOption52 - Append timezone to JSON time
dt += GetTimeZone(); // 2017-03-07T11:08:02-07:00 dt += GetTimeZone(); // 2017-03-07T11:08:02-07:00
} }
return dt; // 2017-03-07T11:08:02-07:00 return dt; // 2017-03-07T11:08:02-07:00 or 2017-03-07T11:08:02.123-07:00
} }
uint32_t UpTime(void) { uint32_t UpTime(void) {