Class: Fluent::JsonNestToFlatOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_json_nest2flat.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/out_json_nest2flat.rb', line 10

def configure(conf)
    super

    @json_keys = conf['json_keys']
    if @json_keys.nil?
        raise Fluent::ConfigError, "json_keys is required!"
    end

    @tag = conf['tag']
    @add_tag_prefix = conf['add_tag_prefix']
    if @tag.nil? && @add_tag_prefix.nil?
        raise Fluent::ConfigError, "tag or add_tag_prefix is required!"
    end

    @enabled_tag = false
    if !@tag.nil?
        @enabled_tag = true
    end

    @json_keys = @json_keys.split(",")

    @ignore_item_keys = conf['ignore_item_keys']

    if !@ignore_item_keys.nil?
        begin
            @ignore_item_keys = JSON.parse(@ignore_item_keys)
        rescue => e
           raise Fluent::ConfigError, "ignore_item_keys is illegal! ignore_item_keys=#{@ignore_item_keys}"
        end
    end
end

#emit(tag, es, chain) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/out_json_nest2flat.rb', line 42

def emit(tag, es, chain)
    es.each { |time, record|
        chain.next

        new_record = nil
        begin
            new_record = _convert_record(record);
        rescue => e
            $log.error "json_data is parse error.", :error=>e.to_s
        end

        if @enabled_tag
            Fluent::Engine.emit(@tag, time, new_record)
        else
            Fluent::Engine.emit("#{@add_tag_prefix}.#{tag}", time, new_record)
        end 
    }
end