Ensure that dates are always parsed with English locale
SimpleDateFormat is parsing dates in a locale-sensitive manner but timestamps in syslog messages are always using English month names (RFC 3164, section 4.1.2).
This commit is contained in:
parent
3a67b21cbf
commit
4996dd00c3
@ -1,11 +1,12 @@
|
||||
package org.graylog2.syslog4j.impl.message;
|
||||
|
||||
import org.graylog2.syslog4j.SyslogMessageIF;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.graylog2.syslog4j.SyslogMessageIF;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* AbstractSyslogMessage provides support for turning POJO (Plain Ol'
|
||||
@ -50,13 +51,13 @@ public abstract class AbstractSyslogMessage implements SyslogMessageIF {
|
||||
}
|
||||
|
||||
protected String generateDate() {
|
||||
String date = new SimpleDateFormat(getDateFormat()).format(new Date());
|
||||
String date = new SimpleDateFormat(getDateFormat(), Locale.ENGLISH).format(new Date());
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
protected String generateTime() {
|
||||
String time = new SimpleDateFormat(getTimeFormat()).format(new Date());
|
||||
String time = new SimpleDateFormat(getTimeFormat(), Locale.ENGLISH).format(new Date());
|
||||
|
||||
return time;
|
||||
}
|
||||
@ -64,8 +65,8 @@ public abstract class AbstractSyslogMessage implements SyslogMessageIF {
|
||||
protected String[] generateDateAndTime(Date date) {
|
||||
String[] dateAndTime = new String[2];
|
||||
|
||||
dateAndTime[0] = new SimpleDateFormat(getDateFormat()).format(date);
|
||||
dateAndTime[1] = new SimpleDateFormat(getTimeFormat()).format(date);
|
||||
dateAndTime[0] = new SimpleDateFormat(getDateFormat(), Locale.ENGLISH).format(date);
|
||||
dateAndTime[1] = new SimpleDateFormat(getTimeFormat(), Locale.ENGLISH).format(date);
|
||||
|
||||
return dateAndTime;
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
package org.graylog2.syslog4j.server.impl.event;
|
||||
|
||||
import org.graylog2.syslog4j.SyslogConstants;
|
||||
import org.graylog2.syslog4j.server.SyslogServerEventIF;
|
||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.graylog2.syslog4j.SyslogConstants;
|
||||
import org.graylog2.syslog4j.server.SyslogServerEventIF;
|
||||
import org.graylog2.syslog4j.util.SyslogUtility;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* SyslogServerEvent provides an implementation of the SyslogServerEventIF interface.
|
||||
@ -91,7 +92,7 @@ public class SyslogServerEvent implements SyslogServerEventIF {
|
||||
String year = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
|
||||
|
||||
String originalDate = this.message.substring(0, datelength - 1) + " " + year;
|
||||
DateFormat dateFormat = new SimpleDateFormat(dateFormatS);
|
||||
DateFormat dateFormat = new SimpleDateFormat(dateFormatS, Locale.ENGLISH);
|
||||
try {
|
||||
this.date = dateFormat.parse(originalDate);
|
||||
|
||||
|
@ -8,6 +8,7 @@ import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* SyslogServerStructuredEvent provides an implementation of the
|
||||
@ -58,7 +59,7 @@ public class StructuredSyslogServerEvent extends SyslogServerEvent {
|
||||
}
|
||||
|
||||
public void setDateTimeFormatter(Object dateTimeFormatter) {
|
||||
this.dateTimeFormatter = (DateTimeFormatter) dateTimeFormatter;
|
||||
this.dateTimeFormatter = ((DateTimeFormatter) dateTimeFormatter).withLocale(Locale.US);
|
||||
}
|
||||
|
||||
protected void parseApplicationName() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user