Class: Fluent::PgJsonOutput

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

Instance Method Summary collapse

Constructor Details

#initializePgJsonOutput

Returns a new instance of PgJsonOutput.



17
18
19
20
21
# File 'lib/fluent/plugin/out_pgjson.rb', line 17

def initialize
  super
  require 'pg'
  @conn = nil
end

Instance Method Details

#configure(conf) ⇒ Object



23
24
25
26
# File 'lib/fluent/plugin/out_pgjson.rb', line 23

def configure(conf)
  super
  @stmt_name = 'insert'
end

#format(tag, time, record) ⇒ Object



36
37
38
# File 'lib/fluent/plugin/out_pgjson.rb', line 36

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#shutdownObject



28
29
30
31
32
33
34
# File 'lib/fluent/plugin/out_pgjson.rb', line 28

def shutdown
  super

  if ! @conn.nil? and ! @conn.finished?
    @conn.close()
  end
end

#write(chunk) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/out_pgjson.rb', line 40

def write(chunk)
  begin
    init_connection
    sql = build_sql(chunk)
    @conn.exec(sql)
  rescue
    begin
      @conn.close()
    rescue
    end

    @conn = nil 
    raise
  end
end