Class: Fluent::RecordReformerOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::RecordReformerOutput
- Defined in:
- lib/fluent/plugin/out_record_reformer.rb
Defined Under Namespace
Classes: PlaceholderExpander, RubyPlaceholderExpander
Constant Summary collapse
- BUILTIN_CONFIGURATIONS =
%W(type tag output_tag remove_keys renew_record keep_keys enable_ruby renew_time_key)
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ RecordReformerOutput
constructor
A new instance of RecordReformerOutput.
Constructor Details
#initialize ⇒ RecordReformerOutput
Returns a new instance of RecordReformerOutput.
7 8 9 10 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 7 def initialize require 'socket' super end |
Instance Method Details
#configure(conf) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 32 def configure(conf) super @map = {} conf.each_pair { |k, v| next if BUILTIN_CONFIGURATIONS.include?(k) conf.has_key?(k) # to suppress unread configuration warning @map[k] = parse_value(v) } # <record></record> directive conf.elements.select { |element| element.name == 'record' }.each { |element| element.each_pair { |k, v| element.has_key?(k) # to suppress unread configuration warning @map[k] = parse_value(v) } } if @remove_keys @remove_keys = @remove_keys.split(',') end if @keep_keys raise Fluent::ConfigError, "out_record_reformer: `renew_record` must be true to use `keep_keys`" unless @renew_record @keep_keys = @keep_keys.split(',') end if @output_tag and @tag.nil? # for lower version compatibility log.warn "out_record_reformer: `output_tag` is deprecated. Use `tag` option instead." @tag = @output_tag end if @tag.nil? raise Fluent::ConfigError, "out_record_reformer: `tag` must be specified" end @placeholder_expander = if @enable_ruby # require utilities which would be used in ruby placeholders require 'pathname' require 'uri' require 'cgi' RubyPlaceholderExpander.new(log) else PlaceholderExpander.new(log) end @hostname = Socket.gethostname end |
#emit(tag, es, chain) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 80 def emit(tag, es, chain) tag_parts = tag.split('.') tag_prefix = tag_prefix(tag_parts) tag_suffix = tag_suffix(tag_parts) placeholders = { 'tag' => tag, 'tags' => tag_parts, 'tag_parts' => tag_parts, 'tag_prefix' => tag_prefix, 'tag_suffix' => tag_suffix, 'hostname' => @hostname, } last_record = nil es.each {|time, record| last_record = record # for debug log new_tag, new_record = reform(@tag, time, record, placeholders) if new_tag if @renew_time_key && new_record.has_key?(@renew_time_key) time = new_record[@renew_time_key].to_i end router.emit(new_tag, time, new_record) end } chain.next rescue => e log.warn "record_reformer: #{e.class} #{e.} #{e.backtrace.first}" log.debug "record_reformer: tag:#{@tag} map:#{@map} record:#{last_record} placeholders:#{placeholders}" end |