Closed cipriancraciun closed 6 months ago
Here is the minimal patch that solves the issue.
diff --git i/src/format.rs w/src/format.rs
index b684ae8..43bff7e 100644
--- i/src/format.rs
+++ w/src/format.rs
@@ -162,25 +162,32 @@ impl Formatter5424 {
impl<T: Display> LogFormat<(u32, StructuredData, T)> for Formatter5424 {
fn format<W: Write>(
&self,
w: &mut W,
severity: Severity,
log_message: (u32, StructuredData, T),
) -> Result<()> {
let (message_id, data, message) = log_message;
+ let timestamp = time::OffsetDateTime::now_utc();
+
+ // Trim timestamp to millisecond resolution according to RFC5424.
+ let timestamp = timestamp
+ .replace_nanosecond(timestamp.nanosecond() / 1000 * 1000)
+ .unwrap();
+
write!(
w,
"<{}>1 {} {} {} {} {} {} {}", // v1
encode_priority(severity, self.facility),
- time::OffsetDateTime::now_utc()
+ timestamp
.format(&time::format_description::well_known::Rfc3339)
.unwrap(),
self.hostname
.as_ref()
.map(|x| &x[..])
.unwrap_or("localhost"),
self.process,
self.pid,
message_id,
self.format_5424_structured_data(data),
According to the RFC 5424 section 6 the timestamp second should have at most 6 digits after the dot (see
TIME-SECFRAC
):Here is an example of what the library produces with RFC 5424 format:
Moreover, citing from RFC 5424, section 6.2.3:
The last example, cited from the RFC explicitly states that nanosecond resolution is not allowed according to the specification.