From 691910f9f55a03eb08f4d5f92a3328480efdee66 Mon Sep 17 00:00:00 2001 From: Cyrille Le Clerc Date: Fri, 29 May 2015 10:45:36 +0200 Subject: [PATCH] Fix #7 RFC3164 timestamp should use localtime instead of UTC --- src/main/java/com/cloudbees/syslog/SyslogMessage.java | 10 +++++++++- .../java/com/cloudbees/syslog/SyslogMessageTest.java | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cloudbees/syslog/SyslogMessage.java b/src/main/java/com/cloudbees/syslog/SyslogMessage.java index cd07182..87e065c 100644 --- a/src/main/java/com/cloudbees/syslog/SyslogMessage.java +++ b/src/main/java/com/cloudbees/syslog/SyslogMessage.java @@ -69,10 +69,18 @@ protected String newObject() { Locale.US, TimeZone.getTimeZone("GMT"), concurrency); + + /** + * According to RFC31614- 4.1.2 HEADER Part of a syslog Packet, + * we should use local time and not GMT. + * + * The TIMESTAMP field is the local time and is in the format of "Mmm dd hh:mm:ss" (without the quote marks) + * + */ rfc3164DateFormat = new ConcurrentDateFormat( "MMM dd HH:mm:ss", Locale.US, - TimeZone.getTimeZone("GMT"), + TimeZone.getDefault(), concurrency); } diff --git a/src/test/java/com/cloudbees/syslog/SyslogMessageTest.java b/src/test/java/com/cloudbees/syslog/SyslogMessageTest.java index b90a945..fb53cc6 100644 --- a/src/test/java/com/cloudbees/syslog/SyslogMessageTest.java +++ b/src/test/java/com/cloudbees/syslog/SyslogMessageTest.java @@ -60,7 +60,7 @@ public void testRfc5424Format() throws Exception { public void testRfc3164Format() throws Exception { Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getTimeZone("GMT")); + cal.setTimeZone(TimeZone.getDefault()); cal.set(2013, Calendar.DECEMBER, 5, 10, 30, 5); cal.set(Calendar.MILLISECOND, 0);