Class: Fluent::GoogleSheetsOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_google_sheets.rb

Instance Method Summary collapse

Instance Method Details

#format(tag, time, record) ⇒ Object



15
16
17
# File 'lib/fluent/plugin/out_google_sheets.rb', line 15

def format(tag, time, record)
  [tag, Time.at(time).strftime('%F %T'), record].to_json + "\n"
end

#write(chunk) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/fluent/plugin/out_google_sheets.rb', line 19

def write(chunk)
  data = chunk.read.each_line.map {|line| JSON.parse(line) }.group_by {|tag, *| tag }

  data.each do |tag, xs|
    ws = worksheet(tag)
    ws.insert_rows(ws.num_rows + 1, xs.map {|_, time, record| (@add_timestamp_column ? [time] : []) + record.values })
    ws.save
  end
end