-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Populate syslog timestamp field when time is available #8643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
* Changed syslog messages from always using NILVALUE for the TIMESTAMP field. * Now uses RFC5424 UTC timestamp format when a valid time is available from RTC. * Falls back to NILVALUE if no valid time is available.
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances syslog messages by populating the timestamp field with RFC5424 UTC timestamps when valid time is available from the RTC, instead of always using NILVALUE ("-").
Key changes:
- Added RTC time retrieval to check if valid time is available
- Implemented RFC5424-compliant UTC timestamp formatting (YYYY-MM-DDTHH:MM:SSZ)
- Falls back to NILVALUE when no valid time exists
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| char timestamp_buffer[21]; | ||
| snprintf(timestamp_buffer, sizeof(timestamp_buffer), "%04d-%02d-%02dT%02d:%02d:%02dZ", | ||
| time_info->tm_year + 1900, time_info->tm_mon + 1, time_info->tm_mday, | ||
| time_info->tm_hour, time_info->tm_min, time_info->tm_sec); | ||
| this->_client->print(timestamp_buffer); | ||
| } else { | ||
| this->_client->print(SYSLOG_NILVALUE); |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gmtime() function can return NULL if the time value is invalid. This could lead to a null pointer dereference when accessing time_info->tm_year. Add a null check before using the returned pointer.
struct tm *time_info = gmtime(×tamp);
if (time_info != NULL) {
char timestamp_buffer[21];
snprintf(timestamp_buffer, sizeof(timestamp_buffer), "%04d-%02d-%02dT%02d:%02d:%02dZ",
time_info->tm_year + 1900, time_info->tm_mon + 1, time_info->tm_mday,
time_info->tm_hour, time_info->tm_min, time_info->tm_sec);
this->_client->print(timestamp_buffer);
} else {
this->_client->print(SYSLOG_NILVALUE);
}| char timestamp_buffer[21]; | |
| snprintf(timestamp_buffer, sizeof(timestamp_buffer), "%04d-%02d-%02dT%02d:%02d:%02dZ", | |
| time_info->tm_year + 1900, time_info->tm_mon + 1, time_info->tm_mday, | |
| time_info->tm_hour, time_info->tm_min, time_info->tm_sec); | |
| this->_client->print(timestamp_buffer); | |
| } else { | |
| this->_client->print(SYSLOG_NILVALUE); | |
| if (time_info != NULL) { | |
| char timestamp_buffer[21]; | |
| snprintf(timestamp_buffer, sizeof(timestamp_buffer), "%04d-%02d-%02dT%02d:%02d:%02dZ", | |
| time_info->tm_year + 1900, time_info->tm_mon + 1, time_info->tm_mday, | |
| time_info->tm_hour, time_info->tm_min, time_info->tm_sec); | |
| this->_client->print(timestamp_buffer); | |
| } else { | |
| this->_client->print(SYSLOG_NILVALUE); | |
| } |
| this->_client->print(F(">1 ")); | ||
|
|
||
| // Format RFC5424 timestamp if valid time is available. | ||
| uint32_t timestamp_sec = getValidTime(RTCQualityDevice, false); |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RTCQualityDevice enum value should be qualified with the RTCQuality:: namespace. Based on other usages in the codebase (e.g., in RedirectablePrint.cpp, NMEAWPL.cpp), this should be RTCQuality::RTCQualityDevice.
uint32_t timestamp_sec = getValidTime(RTCQuality::RTCQualityDevice, false);| uint32_t timestamp_sec = getValidTime(RTCQualityDevice, false); | |
| uint32_t timestamp_sec = getValidTime(RTCQuality::RTCQualityDevice, false); |
Fixes #7609
Changed syslog messages from always using NILVALUE for the TIMESTAMP field. Now uses RFC5424 UTC timestamp format when a valid time is available from RTC. Falls back to NILVALUE if no valid time is available.
🤝 Attestations