Class: Sysloggly::Formatters::SyslogFormatter

Inherits:
SimpleFormatter show all
Defined in:
lib/sysloggly/formatters/syslog_formatter.rb

Instance Attribute Summary

Attributes inherited from SimpleFormatter

#custom_fields, #input_uri

Instance Method Summary collapse

Methods inherited from SimpleFormatter

#datetime_format, #hashify_message, #initialize

Constructor Details

This class inherits a constructor from Sysloggly::Formatters::SimpleFormatter

Instance Method Details

#call(severity, datetime, progname, payload) ⇒ Object

Generate a syslog compat message See RFC3164 4.1.1 - 4.1.3



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sysloggly/formatters/syslog_formatter.rb', line 29

def call(severity, datetime, progname, payload)
  message = "<#{pri(severity)}>#{datetime.strftime(datetime_format)} #{@hostname} "

  # Include process ID in progname/log tag - RFC3164 ยง 5.3
  message << "#{@progname || progname || $0}[#{Process.pid}]: "

  message << MultiJson.dump(hashify_message(payload).merge(custom_fields))
  message << "\r\n"  if ["file", "tcp"].include?(@input_uri.scheme)

  message
end

#pri(severity) ⇒ Object

Syslog specific PRI calculation. See RFC3164 4.1.1



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sysloggly/formatters/syslog_formatter.rb', line 9

def pri(severity)
  severity_value = case severity
                   when "FATAL"
                     0
                   when "ERROR"
                     3
                   when "WARN"
                     4
                   when "INFO"
                     6
                   when "DEBUG"
                     7
                   end
  (@facility << 3) + severity_value
end