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)
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
26 27 28 29 30 31 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 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 26 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] = 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] = 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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 74 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) Engine.emit(new_tag, time, new_record) if new_tag } 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 |