Class: BinlogReaderCommand::Head

Inherits:
Base
  • Object
show all
Includes:
Formattable
Defined in:
lib/fluent/command/binlog_reader.rb

Direct Known Subclasses

Cat

Constant Summary collapse

DEFAULT_HEAD_OPTIONS =
{
  count: 5
}

Constants included from Formattable

Formattable::DEFAULT_OPTIONS

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ Head

Returns a new instance of Head.



168
169
170
171
172
# File 'lib/fluent/command/binlog_reader.rb', line 168

def initialize(argv = ARGV)
  super
  @options.merge!(default_options)
  parse_options!
end

Instance Method Details

#callObject



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/fluent/command/binlog_reader.rb', line 174

def call
  @formatter = lookup_formatter(@options[:format], @options[:config_params])

  File.open(@path, 'rb') do |io|
    i = 1
    Fluent::MessagePackFactory.unpacker(io).each do |(time, record)|
      print @formatter.format(@path, time, record) # path is used for tag
      break if @options[:count] && i == @options[:count]
      i += 1
    end
  end
end