Module: Sysloggly::Client::InstanceMethods
Instance Method Summary collapse
-
#datetime_format ⇒ Object
Specifies the date/time format for this client.
-
#formatter ⇒ Object
Generate a syslog compat message See RFC3164 4.1.1 - 4.1.3.
- #hashify_message(msg) ⇒ Object
-
#pri(severity) ⇒ Object
Syslog specific PRI calculation.
- #setup_options ⇒ Object
Instance Method Details
#datetime_format ⇒ Object
Specifies the date/time format for this client
37 38 39 |
# File 'lib/sysloggly/client.rb', line 37 def datetime_format "%b %e %H:%M:%S" end |
#formatter ⇒ Object
Generate a syslog compat message See RFC3164 4.1.1 - 4.1.3
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sysloggly/client.rb', line 78 def formatter proc do |severity, datetime, progname, msg| processid = Process.pid = "<#{pri(severity)}>#{datetime.strftime(datetime_format)} #{@hostname} " # Include process ID in progname/log tag - RFC3164 § 5.3 << "#{@progname || progname || $0}[#{processid}]: " # Only log JSON to Syslog << MultiJson.dump((msg).merge()) if ['file', 'tcp'].include?(@input_uri.scheme ) << "\r\n" end end end |
#hashify_message(msg) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/sysloggly/client.rb', line 96 def (msg) if msg.is_a?(Hash) msg elsif msg.is_a?(Exception) { exception_class: msg.class.name, message: msg. } elsif msg.is_a?(String) begin JSON.parse(msg) rescue { message: msg } end else { message: msg.inspect } end end |
#pri(severity) ⇒ Object
Syslog specific PRI calculation. See RFC3164 4.1.1
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sysloggly/client.rb', line 60 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 |
#setup_options ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sysloggly/client.rb', line 41 def @hostname = opts[:hostname] || Socket.gethostname.split('.').first @progname = opts[:progname] = opts.except(:hostname, :progname) if ['udp', 'tcp'].include?(@input_uri.scheme) && !@input_uri.path.empty? if @facility = @input_uri.path.split('/')[1] @facility = @facility.to_i unless @facility <= 23 && @facility >= 0 raise Sysloggly::UnknownFacility.new(@facility.to_s) end end else @facility = 23 end end |