module EventMachine

EventMachine HTTP Server HTTP Response-support class

Author

blackhedd (gmail address: garbagecat10).

Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.

This program is made available under the terms of the GPL version 2.

Add EventMachine::file_tail

Public Class Methods

file_tail(path, handler=nil, *args, &block) click to toggle source

Tail a file.

path is the path to the file to tail. handler should be a module implementing 'receive_data' or must be a subclasses of EventMachine::FileTail

For example:

EM::file_tail("/var/log/messages", MyHandler)

If a block is given, and the handler is not specified or does not implement EventMachine::FileTail#receive_data, then it will be called as such:

EM::file_tail(...) do |filetail, line|
  # filetail is the FileTail instance watching the file
  # line is the line read from the file
end
# File lib/event_machine/tail/filetail.rb, line 462
def self.file_tail(path, handler=nil, *args, &block)
  # This code mostly styled on what EventMachine does in many of it's other
  # methods.
  args = [path, *args]
  klass = klass_from_handler(EventMachine::FileTail, handler, *args);
  c = klass.new(*args, &block)
  return c
end
glob_tail(glob, handler=nil, *args, &block) click to toggle source

Watch a glob and tail any files found.

  • glob - a string path or glob, such as /var/log/*.log

  • handler - a module or subclass of EventMachine::FileGlobWatchTail. handler can be omitted if you give a block.

If you give a block and omit the handler parameter, then the behavior is that your block is called for every line read from any file the same way EventMachine::file_tail does when called with a block.

See EventMachine::FileGlobWatchTail for the callback methods.
See EventMachine::file_tail for more information about block behavior.
# File lib/event_machine/tail/globwatcher.rb, line 264
def self.glob_tail(glob, handler=nil, *args, &block)
  handler = EventMachine::FileGlobWatchTail if handler == nil
  args.unshift(glob)
  klass = klass_from_handler(EventMachine::FileGlobWatchTail, handler, *args)
  c = klass.new(*args, &block)
  return c
end
watch_glob(glob, handler=nil, *args) { |c| ... } click to toggle source

Watch a glob for any files.

The remaining (optional) arguments are passed to your handler like this:

If you call this:
  EventMachine.watch_glob("/var/log/*.log", YourHandler, 1, 2, 3, ...)
This will be invoked when new matching files are found:
  YourHandler.new(path_found, 1, 2, 3, ...)
  ^ path_found is the new path found by the glob

See EventMachine::FileGlobWatch for the callback methods.

# File lib/event_machine/tail/globwatcher.rb, line 285
def self.watch_glob(glob, handler=nil, *args)
  # This code mostly styled on what EventMachine does in many of it's other
  # methods.
  args = [glob, *args]
  klass = klass_from_handler(EventMachine::FileGlobWatch, handler, *args);
  c = klass.new(*args)
  yield c if block_given?
  return c
end