lib/syslog-sd/notifier.rb in syslog-sd-1.2.2 vs lib/syslog-sd/notifier.rb in syslog-sd-1.2.3

- old
+ new

@@ -1,19 +1,20 @@ module SyslogSD # syslog notifier. class Notifier - attr_accessor :enabled, :collect_file_and_line + attr_accessor :enabled, :collect_file_and_line, :timestamp_as_float attr_reader :level, :default_options, :level_mapping # +host+ and +port+ are host/ip and port of syslog server. # +default_options+ is used in notify! def initialize(host = 'localhost', port = 514, default_options = {}) @enabled = true @collect_file_and_line = true @sd_id = "_@37797" self.level = SyslogSD::DEBUG + self.timestamp_as_float = false self.default_options = default_options self.default_options['host'] ||= Socket.gethostname self.default_options['level'] ||= SyslogSD::UNKNOWN self.default_options['facility'] ||= 'syslog-sd-rb' @@ -182,10 +183,10 @@ @hash['level'] = @level_mapping[@hash['level']] prival = 128 + @hash.delete('level') # 128 = 16(local0) * 8 t = Time.now.utc - timestamp = t.strftime("%Y-%m-%dT%H:%M:%S.#{t.usec.to_s[0,3]}Z") + timestamp = timestamp_as_float ? t.to_f : t.strftime("%Y-%m-%dT%H:%M:%S.#{t.usec.to_s[0,3]}Z") host = @hash.delete('host') facility = @hash.delete('facility') || '-' procid = @hash.delete('procid') msgid = @hash.delete('msgid') || '-' short_message = @hash.delete('short_message')