send NIL ("-") as timestamp if time source is not valid (#12588)
This commit is contained in:
committed by
Jonathan Swoboda
parent
b055f5b4bf
commit
086ec770ea
@@ -34,7 +34,15 @@ void Syslog::log_(const int level, const char *tag, const char *message, size_t
|
|||||||
severity = LOG_LEVEL_TO_SYSLOG_SEVERITY[level];
|
severity = LOG_LEVEL_TO_SYSLOG_SEVERITY[level];
|
||||||
}
|
}
|
||||||
int pri = this->facility_ * 8 + severity;
|
int pri = this->facility_ * 8 + severity;
|
||||||
auto timestamp = this->time_->now().strftime("%b %e %H:%M:%S");
|
auto now = this->time_->now();
|
||||||
|
std::string timestamp;
|
||||||
|
if (now.is_valid()) {
|
||||||
|
timestamp = now.strftime("%b %e %H:%M:%S");
|
||||||
|
} else {
|
||||||
|
// RFC 5424: A syslog application MUST use the NILVALUE as TIMESTAMP if the syslog application is incapable of
|
||||||
|
// obtaining system time.
|
||||||
|
timestamp = "-";
|
||||||
|
}
|
||||||
size_t len = message_len;
|
size_t len = message_len;
|
||||||
// remove color formatting
|
// remove color formatting
|
||||||
if (this->strip_ && message[0] == 0x1B && len > 11) {
|
if (this->strip_ && message[0] == 0x1B && len > 11) {
|
||||||
|
|||||||
Reference in New Issue
Block a user