Class: Fluent::Client::Core
- Inherits:
-
Object
- Object
- Fluent::Client::Core
- Defined in:
- lib/fluent/client/core.rb
Instance Method Summary collapse
- #create_parser(format, time_format, keys) ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
- #parse_text(format, time_format, keys, buffer = STDIN.read) ⇒ Object
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
4 5 |
# File 'lib/fluent/client/core.rb', line 4 def initialize end |
Instance Method Details
#create_parser(format, time_format, keys) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fluent/client/core.rb', line 7 def create_parser(format, time_format, keys) if format == 'multiline' STDERR.puts 'multiline format is not support!' exit 1 end if format[0] == '/' && format[format.length - 1] == '/' format = format.gsub(/^\/(.+)\/$/, '\1') parser = Fluent::TextParser::RegexpParser.new(Regexp.new(format)) else factory = Fluent::TextParser::TEMPLATE_REGISTRY.lookup(format) parser = factory.call end parser.configure('time_format' => time_format) unless time_format.nil? parser.configure('keys' => keys) unless keys.nil? parser end |
#parse_text(format, time_format, keys, buffer = STDIN.read) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fluent/client/core.rb', line 25 def parse_text(format, time_format, keys, buffer = STDIN.read) results = [] parser = create_parser(format, time_format, keys) begin buffer.lines.each_with_index do |line, i| line = line.strip parsed_time, parsed = parser.call(line) if parsed.nil? puts "format error! line #{i + 1} [#{line}]" else puts parsed end results << parsed unless parsed.nil? end rescue ArgumentError, RegexpError => e STDERR.puts "\n#{e.}\n#{e.backtrace.join("\n")}" parsed_time = parsed = nil end results end |