class LogStash::Inputs::Stdin

Read events from standard input.

By default, each event is assumed to be one line. If you want to join lines, you'll want to use the multiline filter.

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/stdin.rb, line 17
def register
  @host = Socket.gethostname
end
run(queue) click to toggle source
# File lib/logstash/inputs/stdin.rb, line 21
def run(queue) 
  while true
    begin
      # Based on some testing, there is no way to interrupt an IO.sysread nor
      # IO.select call in JRuby. Bummer :(
      data = $stdin.sysread(16384)
      @codec.decode(data) do |event|
        decorate(event)
        event["host"] = @host
        queue << event
      end
    rescue EOFError, LogStash::ShutdownSignal
      # stdin closed or a requested shutdown
      break
    end
  end # while true
  finished
end
teardown() click to toggle source
# File lib/logstash/inputs/stdin.rb, line 41
def teardown
  @logger.debug("stdin shutting down.")
  $stdin.close rescue nil
  finished
end