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.



158
159
160
161
162
# File 'lib/fluent/command/binlog_reader.rb', line 158

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

Instance Method Details

#callObject



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/fluent/command/binlog_reader.rb', line 164

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

  File.open(@path, 'r') 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