Class: Fluent::NamedPipeInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_named_pipe.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fluent/plugin/in_named_pipe.rb', line 21

def configure(conf)
  super

  begin
    pipe = PluginNamedPipe::Fifo.new(@path, :r)
    pipe.close # just to try open
  rescue => e
    raise ConfigError, "#{e.class}: #{e.message}"
  end

  @parser = Plugin.new_parser(@format)
  @parser.configure(conf)
end

#runObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/in_named_pipe.rb', line 47

def run
  @pipe = PluginNamedPipe::Fifo.new(@path, :r)

  while @running
    begin
      line = @pipe.readline # blocking
      next if line.nil?
      
      @parser.parse(line) do |time, record|
        if time and record
          router.emit(@tag, time, record)
        else
          log.warn "Pattern not match: #{line.inspect}"
        end
      end
    rescue => e
      log.error "in_named_pipe: unexpected error", :error_class => e.class, :error => e.to_s
      log.error_backtrace
    end
  end
end

#shutdownObject



41
42
43
44
45
# File 'lib/fluent/plugin/in_named_pipe.rb', line 41

def shutdown
  @running = false
  @thread.join
  @pipe.close
end

#startObject



35
36
37
38
39
# File 'lib/fluent/plugin/in_named_pipe.rb', line 35

def start
  super
  @running = true
  @thread = Thread.new(&method(:run))
end