Class: EventShipper::LogTailer
- Inherits:
-
Object
- Object
- EventShipper::LogTailer
- Defined in:
- lib/event_shipper/log_tailer.rb
Instance Method Summary collapse
-
#initialize(path, transport) ⇒ LogTailer
constructor
A new instance of LogTailer.
- #issue(line) ⇒ Object
- #join ⇒ Object
- #start ⇒ Object
- #thread_main(once = false) ⇒ Object
Constructor Details
#initialize(path, transport) ⇒ LogTailer
Returns a new instance of LogTailer.
10 11 12 13 14 |
# File 'lib/event_shipper/log_tailer.rb', line 10 def initialize path, transport @path = path @transport = transport @host = Socket.gethostname end |
Instance Method Details
#issue(line) ⇒ Object
36 37 38 39 |
# File 'lib/event_shipper/log_tailer.rb', line 36 def issue line event = Event.new @host, @path, line @transport.send event.to_hash end |
#join ⇒ Object
41 42 43 |
# File 'lib/event_shipper/log_tailer.rb', line 41 def join @thread.join end |
#start ⇒ Object
16 17 18 19 |
# File 'lib/event_shipper/log_tailer.rb', line 16 def start @thread = Thread.new(&method(:thread_main)) @thread.abort_on_exception = true end |
#thread_main(once = false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/event_shipper/log_tailer.rb', line 21 def thread_main once=false File.open(@path) do |log| log.seek 0, IO::SEEK_END log.extend File::Tail log.max_interval = 5 log.interval = 1 log.tail do |line| issue line return if once end end end |