From 763769aad21345a0cdd6d0f8ffda7590e2817edb Mon Sep 17 00:00:00 2001 From: Mikko Kortelainen Date: Wed, 4 Dec 2024 10:52:47 +0200 Subject: [PATCH] use timestamp.toEpochMilli() instead of Instant (#49) * use timestamp.toEpochMilli() instead of Instant to avoid https://github.com/teragrep/rlo_14/issues/10 * test that timestamp matches to an expected pattern --- .../com/teragrep/jla_01/syslog/SyslogRecordTimestamp.java | 2 +- .../java/com/teragrep/jla_01/RlpLogbackAppenderTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/teragrep/jla_01/syslog/SyslogRecordTimestamp.java b/src/main/java/com/teragrep/jla_01/syslog/SyslogRecordTimestamp.java index b3e00b3..35b6cf8 100644 --- a/src/main/java/com/teragrep/jla_01/syslog/SyslogRecordTimestamp.java +++ b/src/main/java/com/teragrep/jla_01/syslog/SyslogRecordTimestamp.java @@ -34,6 +34,6 @@ public SyslogRecordTimestamp(SyslogRecord syslogRecord, Instant timestamp) { @Override public SyslogMessage getRecord() { - return syslogRecord.getRecord().withTimestamp(timestamp); + return syslogRecord.getRecord().withTimestamp(timestamp.toEpochMilli()); } } diff --git a/src/test/java/com/teragrep/jla_01/RlpLogbackAppenderTest.java b/src/test/java/com/teragrep/jla_01/RlpLogbackAppenderTest.java index 18dfe42..00e0bd0 100644 --- a/src/test/java/com/teragrep/jla_01/RlpLogbackAppenderTest.java +++ b/src/test/java/com/teragrep/jla_01/RlpLogbackAppenderTest.java @@ -97,6 +97,11 @@ public void testDefaultSyslogMessage() { Assertions.assertEquals("localhost", rfc5424Frame.hostname.toString()); Assertions.assertEquals("appName", rfc5424Frame.appName.toString()); + + Pattern timestampPattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}Z"); + + Assertions.assertTrue(timestampPattern.matcher(rfc5424Frame.timestamp.toString()).matches()); + Assertions.assertEquals("DEBUG logger - "+testPayload+"\n", rfc5424Frame.msg.toString()); }