Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date format is getting changed after converting syslog object to toRfc5424SyslogMessage #36

Open
arjunpidugu642 opened this issue Jul 18, 2019 · 10 comments

Comments

@arjunpidugu642
Copy link

Hi,

Require date as below format in my Syslog message

"2019-07-18T18:56:38.001+05:30"

Setting date using below API.

syslogMessage.setTimestamp

But After converting syslogMessage object to toRfc5424SyslogMessage and my format of date is changed as below.
"2019-07-18T13:26:38.001Z".
Is there any way to achieve my requirement?

is it possible to provide setTimestamp(String date) API which accepts string instead of Date object?

@arjunpidugu642
Copy link
Author

Hi ,

Any update on above query?

@cyrille-leclerc
Copy link
Contributor

cyrille-leclerc commented Jul 23, 2019

Date formatting in the syslog-java-client

Dates are formatted according to the RFC 5424 (and RFC 3339) hard coding the locale to US and the time zone to GMT.

See https://github.com/CloudBees-community/syslog-java-client/blob/syslog-java-client-1.1.7/src/main/java/com/cloudbees/syslog/SyslogMessage.java#L71

new ConcurrentDateFormat(
                "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
                Locale.US,
                TimeZone.getTimeZone("GMT"),
                concurrency);

Specifications

RFC 5424 - The Syslog Protocol

https://tools.ietf.org/html/rfc5424#section-6.2.3

   The TIMESTAMP field is a formalized timestamp derived from [RFC3339].

   Whereas [RFC3339] makes allowances for multiple syntaxes, this
   document imposes further restrictions.  The TIMESTAMP value MUST
   follow these restrictions:

   o  The "T" and "Z" characters in this syntax MUST be upper case.

   o  Usage of the "T" character is REQUIRED.

   o  Leap seconds MUST NOT be used.

   The originator SHOULD include TIME-SECFRAC if its clock accuracy and
   performance permit.  The "timeQuality" SD-ID described in Section 7.1
   allows the originator to specify the accuracy and trustworthiness of
   the timestamp.

   A syslog application MUST use the NILVALUE as TIMESTAMP if the syslog
   application is incapable of obtaining system time.

RFC 3339 Date and Time on the Internet: Timestamps

https://tools.ietf.org/html/rfc3339#section-5.6

5.6. Internet Date/Time Format

   The following profile of ISO 8601 [ISO8601] dates SHOULD be used in
   new protocols on the Internet.  This is specified using the syntax
   description notation defined in [ABNF].

   date-fullyear   = 4DIGIT
   date-month      = 2DIGIT  ; 01-12
   date-mday       = 2DIGIT  ; 01-28, 01-29, 01-30, 01-31 based on
                             ; month/year
   time-hour       = 2DIGIT  ; 00-23
   time-minute     = 2DIGIT  ; 00-59
   time-second     = 2DIGIT  ; 00-58, 00-59, 00-60 based on leap second
                             ; rules
   time-secfrac    = "." 1*DIGIT
   time-numoffset  = ("+" / "-") time-hour ":" time-minute
   time-offset     = "Z" / time-numoffset

   partial-time    = time-hour ":" time-minute ":" time-second
                     [time-secfrac]
   full-date       = date-fullyear "-" date-month "-" date-mday
   full-time       = partial-time time-offset

   date-time       = full-date "T" full-time

      NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this
      syntax may alternatively be lower case "t" or "z" respectively.

      This date/time format may be used in some environments or contexts
      that distinguish between the upper- and lower-case letters 'A'-'Z'
      and 'a'-'z' (e.g. XML).  Specifications that use this format in
      such environments MAY further limit the date/time syntax so that
      the letters 'T' and 'Z' used in the date/time syntax must always
      be upper case.  Applications that generate this format SHOULD use
      upper case letters.

      NOTE: ISO 8601 defines date and time separated by "T".
      Applications using this syntax may choose, for the sake of
      readability, to specify a full-date and full-time separated by
      (say) a space character.

@cyrille-leclerc
Copy link
Contributor

@arjunpidugu642 you are asking to use another timezone in the syslog timestamp than the GMT timezone, correct?

Would it make sense to use the time zone of the server on which the java-syslog-client runs? java.util.TimeZone#getDefault()

https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html#getDefault--

public static TimeZone getDefault()
Gets the default TimeZone of the Java virtual machine. If the cached default TimeZone is available, its clone is returned. Otherwise, the method takes the following steps to determine the default time zone.
 * Use the user.timezone property value as the default time zone ID if it's available.
 * Detect the platform time zone ID. The source of the platform time zone and ID mapping may vary with implementation.
 * Use GMT as the last resort if the given or detected time zone ID is unknown.
The default TimeZone created from the ID is cached, and its clone is returned. The user.timezone property value is set to the ID upon return.

@arjunpidugu642
Copy link
Author

As per RFC 5424 and RFC 3339, We need to follow timestamp with respect to time zone which we can achieve using Coordinated Universal Time(UTC).
T indicates date time and Z indicates time zone whereas Z is not required if we have time stamp with an offset from UTC.
2019-07-19T21:19:51+05:30 (with an offset of +05:30 from UTC) equivalent to 2019-07-19T16:49:51Z in UTC => Both are valid according to RFC

But as per your code

@cyrille-leclerc
Copy link
Contributor

@arjunpidugu642

  • what would be the date format for your case?
  • is it the timezone not being changed to GMT that is the thing that matters the most? or the formatting of the date?

From what I remember, I picked "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" because it's what I found for RFC 5424 / 3329.

@arjunpidugu642
Copy link
Author

Thanks a lot for your response.

I require below timestamp format " yyyy-MM-dd'T'HH:mm:ss.SSSXXX"

@arjunpidugu642
Copy link
Author

what would be the date format for your case? ->[My Answer] " yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
is it the timezone not being changed to GMT that is the thing that matters the most? or the formatting of the date? -> [Answer] Timezone is being changed to GMT but my request is about format of date.

Please find below examples as per RFC 3339:

"""1985-04-12T23:20:50.52Z -> This represents 20 minutes and 50.52 seconds after the 23rd hour of
April 12th, 1985 in UTC.
1996-12-19T16:39:57-08:00 -> This represents 39 minutes and 57 seconds after the 16th hour of
December 19th, 1996 with an offset of -08:00 from UTC (Pacific
Standard Time). Note that this is equivalent to 1996-12-20T00:39:57Z
in UTC.
1990-12-31T23:59:60Z -> This represents the leap second inserted at the end of 1990."""

So, According to RFC3339. 1996-12-19T16:39:57-08:00( "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") is equavalent to 1996-12-20T00:39:57Z("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") and both are valid date formats.

My requirement is to send syslog message in below date format -> "yyyy-MM-dd'T'HH:mm:ss.SSSXXX".

Please help me on this.

@arjunpidugu642
Copy link
Author

@cyrille-leclerc ,

Can you please help me on this.

@cyrille-leclerc
Copy link
Contributor

I have started to introduce more configurability for the time format and timezone, I need to adapt the unit tests as well.

@arjunpidugu642
Copy link
Author

Thanks @cyrille-leclerc .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants