Skip to content

TimeZone offset is not integrated in the event date #43

@jeromevalentin

Description

@jeromevalentin

For all log events send to syslog with ain, the event date is computed by calling: Syslogger.getDate() which is implemented as follow:

/**
 * Get current date in syslog format.
 * @returns {String}
 */
SysLogger.prototype.getDate = function() {
    return new Date().toISOString();
}

This is leading to store all events in syslog with a date in UTC while other applications are sending ISO string with TimeZone offset integrated. This is very confusing when reading logs !

A simple fix, would be to replace getDate implementation as follow:

/**
 * Get current date in syslog format.
 * @returns {String}
 */
SysLogger.prototype.getDate = function() {
      var date = new Date()
      var tzo = -date.getTimezoneOffset(),
          dif = tzo >= 0 ? '+' : '-',
          pad = function(num) {
              var norm = Math.abs(Math.floor(num));
              return (norm < 10 ? '0' : '') + norm;
          };
      return date.getFullYear() +
          '-' + pad(date.getMonth() + 1) +
          '-' + pad(date.getDate()) +
          'T' + pad(date.getHours()) +
          ':' + pad(date.getMinutes()) +
          ':' + pad(date.getSeconds()) +
          dif + pad(tzo / 60) +
          ':' + pad(tzo % 60);
  }

implementation adapted from https://stackoverflow.com/questions/17415579/how-to-iso-8601-format-a-date-with-timezone-offset-in-javascript

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions