Class: RemoteSyslog::FileTailReader
- Inherits:
-
Object
- Object
- RemoteSyslog::FileTailReader
- Defined in:
- lib/remote_syslog/file_tail_reader.rb
Instance Method Summary collapse
-
#initialize(path, options = {}, &block) ⇒ FileTailReader
constructor
A new instance of FileTailReader.
- #run ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(path, options = {}, &block) ⇒ FileTailReader
Returns a new instance of FileTailReader.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/remote_syslog/file_tail_reader.rb', line 5 def initialize(path, = {}, &block) @path = path @callback = [:callback] || block @logger = [:logger] || Logger.new(STDERR) @tag = [:program] || File.basename(path) # Remove characters that can't be in a tag @tag = @tag.gsub(%r{[: \]\[\\]+}, '-') # Make sure the tag isn't too long if @tag.length > 32 @tag = @tag[0..31] end @logger.debug "Watching #{path} with FileTailReader" start end |
Instance Method Details
#run ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/remote_syslog/file_tail_reader.rb', line 30 def run File::Tail::Logfile.tail(@path) do |line| EventMachine.schedule do @callback.call(@tag, line) end end rescue => e @logger.error "Unhandled FileTailReader Exception: #{e.class}: #{e.}:\n\t#{e.backtrace.join("\n\t")}" end |
#start ⇒ Object
24 25 26 27 28 |
# File 'lib/remote_syslog/file_tail_reader.rb', line 24 def start @thread = Thread.new do run end end |