eventmachine-tail 0.0.1 → 0.1.2775

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,7 @@ class EventMachine::FileTail
16
16
  def initialize(path, startpos=0)
17
17
  @path = path
18
18
  @logger = Logger.new(STDOUT)
19
+ @logger.level = Logger::WARN
19
20
 
20
21
  #@need_scheduling = true
21
22
  open
@@ -112,6 +113,7 @@ class EventMachine::FileTail::FileWatcher < EventMachine::FileWatch
112
113
  def initialize(filestream)
113
114
  @filestream = filestream
114
115
  @logger = Logger.new(STDOUT)
116
+ @logger.level = Logger::WARN
115
117
  end
116
118
 
117
119
  def file_modified
@@ -141,22 +143,3 @@ module EventMachine
141
143
  return c
142
144
  end # def self.file_tail
143
145
  end # module EventMachine
144
-
145
- if __FILE__ == $0
146
- class Reader < EventMachine::FileTail
147
- def initialize(*args)
148
- super(*args)
149
- @buffer = BufferedTokenizer.new
150
- end
151
-
152
- def receive_data(data)
153
- @buffer.extract(data).each do |line|
154
- ap [path, line]
155
- end
156
- end
157
- end
158
-
159
- EventMachine::run do
160
- fw = EventMachine::filestream("/var/log/user.log", Reader)
161
- end
162
- end # if __FILE__ == $0
@@ -1,18 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "rubygems" if __FILE__ == $0
4
3
  require "set"
5
4
  require "eventmachine"
6
- require "ap"
7
5
  require "logger"
8
-
9
- require "filetail"
6
+ require "em/filetail"
10
7
 
11
8
  class EventMachine::FileGlobWatch
12
9
  def initialize(pathglob, handler, interval=60)
13
10
  @pathglob = pathglob
14
11
  @handler = handler
15
12
  @files = Set.new
13
+ @logger = Logger.new(STDOUT)
14
+ @logger.level = Logger::WARN
16
15
 
17
16
  EM.next_tick do
18
17
  find_files
@@ -36,14 +35,13 @@ class EventMachine::FileGlobWatch
36
35
  end # def find_files
37
36
 
38
37
  def watch(path)
39
- puts "Watching #{path}"
38
+ @logger.info "Watching #{path}"
40
39
  @files.add(path)
41
40
  @handler.file_found(path)
42
41
  end # def watch
43
42
  end # class EventMachine::FileGlobWatch
44
43
 
45
- class EventMachine::FileGlobWatchHandler
46
- LOGGER = Logger.new(STDOUT)
44
+ class EventMachine::FileGlobWatchTail
47
45
  def initialize(handler=nil)
48
46
  @handler = handler
49
47
  end
@@ -60,28 +58,9 @@ end # class EventMachine::FileGlobWatchHandler
60
58
  module EventMachine
61
59
  def self.glob_tail(glob, handler=nil, *args)
62
60
  handler = EventMachine::FileGlobHandler if handler == nil
63
- klass = klass_from_handler(EventMachine::FileGlobWatchHandler, handler, *args)
61
+ klass = klass_from_handler(EventMachine::FileGlobWatchTail, handler, *args)
64
62
  c = klass.new(*args)
65
63
  yield c if block_given?
66
64
  return c
67
65
  end
68
66
  end
69
-
70
- if __FILE__ == $0
71
- class Reader < EventMachine::FileTail
72
- def initialize(*args)
73
- super(*args)
74
- @buffer = BufferedTokenizer.new
75
- end
76
-
77
- def receive_data(data)
78
- @buffer.extract(data).each do |line|
79
- ap [path, line]
80
- end
81
- end
82
- end
83
-
84
- EventMachine.run do
85
- EventMachine::FileGlobWatch.new("/var/log/*.log", EventMachine::FileGlobWatchHandler.new(Reader))
86
- end
87
- end
@@ -0,0 +1,2 @@
1
+ require 'em/filetail'
2
+ require 'em/globwatcher'
@@ -0,0 +1,33 @@
1
+ require "rubygems"
2
+ require "eventmachine"
3
+ require "eventmachine-tail"
4
+ require "ap"
5
+
6
+ class Reader < EventMachine::FileTail
7
+ def initialize(*args)
8
+ super(*args)
9
+ @buffer = BufferedTokenizer.new
10
+ end
11
+
12
+ def receive_data(data)
13
+ @buffer.extract(data).each do |line|
14
+ ap [path, line]
15
+ end
16
+ end
17
+ end
18
+
19
+ def main(args)
20
+ if args.length == 0
21
+ puts "Usage: #{$0} <path_or_glob> [path_or_glob2] [...]"
22
+ return 1
23
+ end
24
+
25
+ EventMachine.run do
26
+ handler = EventMachine::FileGlobWatchTail.new(Reader)
27
+ args.each do |path|
28
+ EventMachine::FileGlobWatch.new(path, handler)
29
+ end
30
+ end
31
+ end # def main
32
+
33
+ exit(main(ARGV))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-tail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.2775
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Sissel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-11 00:00:00 -07:00
12
+ date: 2010-04-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,8 +31,10 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
+ - lib/eventmachine-tail.rb
34
35
  - lib/em/filetail.rb
35
36
  - lib/em/globwatcher.rb
37
+ - samples/glob-tail.rb
36
38
  has_rdoc: true
37
39
  homepage: http://code.google.com/p/semicomplete/wiki/EventMachine-Tail
38
40
  licenses: []