Class: Fluent::MapOutput

Inherits:
Output
  • Object
show all
Includes:
MapConfigParam, ParseMap::Mixin
Defined in:
lib/fluent/plugin/out_map.rb

Constant Summary

Constants included from ParseMap::Mixin

ParseMap::Mixin::MMAP_MAX_NUM

Instance Method Summary collapse

Methods included from ParseMap::Mixin

#check_mmap_range, #parse_map, #parse_multimap

Methods included from MapConfigParam

included

Instance Method Details

#configure(conf) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/fluent/plugin/out_map.rb', line 41

def configure(conf)
  super
  @format = determine_format()
  configure_format()
  @map = create_map(conf)
  @map_support = Fluent::MapSupport.new(@map, self)
end

#configure_formatObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fluent/plugin/out_map.rb', line 61

def configure_format()
  case @format
  when "map"
    # pass
  when "record"
    @tag ||= @key
    raise Fluent::ConfigError, "multi and 3 parameters(tag, time, and record) are not compatible" if @multi
  when "multimap"
    # pass.
  else
    raise Fluent::ConfigError, "format #{@format} is invalid."
  end
end

#create_map(conf) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fluent/plugin/out_map.rb', line 75

def create_map(conf)
  # return string like double array.
  case @format
  when "map"
    parse_map()
  when "record"
    "[[#{@tag}, #{@time}, #{@record}]]"
  when "multimap"
    parse_multimap(conf)
  end
end

#determine_formatObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/out_map.rb', line 49

def determine_format()
  if @format
    @format
  elsif @map
    "map"
  elsif (@tag || @key) && @time && @record
    "record"
  else
    raise Fluent::ConfigError, "Any of map, 3 parameters(tag, time, and record) or format is required "
  end
end

#emit(tag, es, chain) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fluent/plugin/out_map.rb', line 87

def emit(tag, es, chain)
  begin
    tag_output_es = @map_support.do_map(tag, es)
    tag_output_es.each_pair do |tag, output_es|
      router.emit_stream(tag, output_es)
    end
    chain.next
    tag_output_es
  rescue SyntaxError => e
    chain.next
    log.error "map command is syntax error: #{@map}"
    e #for test
  end
end