Class: LogStash::Inputs::Stdin

Inherits:
Base show all
Defined in:
lib/logstash/inputs/stdin.rb

Overview

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.

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes inherited from Base

#params, #threadable

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize, #tag

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Inputs::Base

Instance Method Details

#registerObject



17
18
19
# File 'lib/logstash/inputs/stdin.rb', line 17

def register
  @host = Socket.gethostname
end

#run(queue) ⇒ Object

def register



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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

#teardownObject



41
42
43
44
45
# File 'lib/logstash/inputs/stdin.rb', line 41

def teardown
  @logger.debug("stdin shutting down.")
  $stdin.close rescue nil
  finished
end