Class: RFC5424::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rfc5424/formatter.rb

Constant Summary collapse

Format =
"<%d>1 %s %s %s %s %s %s %s"

Class Method Summary collapse

Class Method Details

.format(priority: 14, timestamp: nil, log: "", hostname: "-", app_name: "-", proc_id: "-", msg_id: "-", sd: "-") ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rfc5424/formatter.rb', line 8

def format(
  priority: 14,
  timestamp: nil,
  log: "",
  hostname: "-",
  app_name: "-",
  proc_id: "-",
  msg_id: "-",
  sd: "-"
)
  Format % [priority, format_time(timestamp), hostname[0..254], app_name[0..47], proc_id[0..127], msg_id[0..31], sd, log]
end

.format_time(timestamp) ⇒ Object



21
22
23
24
25
26
# File 'lib/rfc5424/formatter.rb', line 21

def format_time(timestamp)
  return "-" if timestamp.nil?
  return Time.at(timestamp.to_r).utc.to_datetime.rfc3339(6) if timestamp.is_a?(Fluent::EventTime)

  DateTime.strptime(timestamp.to_s, '%s').rfc3339(6)
end