plextail 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,11 +22,11 @@ The line will be sent through to Heroku using the provided details. If you want
22
22
  You can customise the following attributes on the yielded line object:
23
23
 
24
24
  * `token` – the logplex token,
25
- * `version` – the logplex version, which defaults to '<134>1',
26
- * `timestamp` – the timestamp for the line, which defaults to the current time, in the following format: '%Y-%m-%dT%H:%M:%S.ms+00:00',
27
- * `hostname` – host name of the log source (doesn't seem to impact Heroku's output),
25
+ * `version` – the logplex version, which defaults to `<134>1`,
26
+ * `timestamp` – the timestamp for the line, which defaults to the current time, in the following format: `%Y-%m-%dT%H:%M:%S.ms+00:00`,
27
+ * `hostname` – host name of the log source (doesn't seem to impact Heroku's output), defaults to your computer's host name,
28
28
  * `process_id` – the source of the log file (e.g. web.1)
29
- * `message_id` – defaults to '- -', and
29
+ * `message_id` – defaults to `- -`, and
30
30
  * `message` – the remainder/core of the log line, which defaults to the entire raw line from the file.
31
31
 
32
32
  The line also has two attributes available to help any custom logic you may involve in the processing: `file` (the file that has a new line appended) and `raw` (the raw line that has appeared in the file).
data/lib/plextail/line.rb CHANGED
@@ -8,13 +8,15 @@ class Plextail::Line
8
8
  attr_accessor :file, :raw, :token, :version, :timestamp, :hostname,
9
9
  :process_id, :message_id, :message
10
10
 
11
- def initialize(file, raw)
11
+ def initialize(file, raw, &block)
12
12
  @file, @raw = file, raw
13
13
  @version = DEFAULTS[:version]
14
14
  @timestamp = current_timestamp
15
15
  @hostname = DEFAULTS[:hostname]
16
16
  @message_id = DEFAULTS[:message_id]
17
17
  @message = raw.dup
18
+
19
+ block.call self if block_given?
18
20
  end
19
21
 
20
22
  def to_s
@@ -9,21 +9,11 @@ class Plextail::Tracker
9
9
  end
10
10
 
11
11
  def pipe(&block)
12
- file = Dir[glob].first
13
- PTY.spawn("tail -f #{glob}") do |stdin, stdout, pid|
14
- stdin.each do |string|
15
- string.strip!
16
- if string[/^==> (.+) <==$/]
17
- file = $1
18
- elsif string.length > 0
19
- line = Plextail::Line.new file, string
20
- block.call line
21
- to_plex line
22
- end
23
- end
12
+ if @glob.empty?
13
+ pipe_from_input nil, &block
14
+ else
15
+ pipe_from_glob Dir[glob].first, &block
24
16
  end
25
- rescue PTY::ChildExited
26
- puts "The child process exited!"
27
17
  end
28
18
 
29
19
  private
@@ -36,6 +26,31 @@ class Plextail::Tracker
36
26
  end
37
27
  end
38
28
 
29
+ def pipe_from_glob(file, &block)
30
+ PTY.spawn("tail -f #{glob}") do |stdin, stdout, pid|
31
+ stdin.each do |string|
32
+ file = process_line file, string, &block
33
+ end
34
+ end
35
+ rescue PTY::ChildExited
36
+ puts "The child process exited!"
37
+ end
38
+
39
+ def pipe_from_input(file, &block)
40
+ ARGF.each_line do |string|
41
+ file = process_line file, string, &block
42
+ end
43
+ end
44
+
45
+ def process_line(file, string, &block)
46
+ string.strip!
47
+ return $1 if string[/^==> (.+) <==$/]
48
+
49
+ to_plex Plextail::Line.new file, string, &block if string.length > 0
50
+
51
+ file
52
+ end
53
+
39
54
  def to_plex(line)
40
55
  connection.basic_auth 'token', line.token
41
56
  connection.post('/logs', line.to_s) do |request|
data/plextail.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'plextail'
4
- spec.version = '0.0.1'
4
+ spec.version = '0.0.2'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = 'Pipes tailed files to Heroku Logplex'
@@ -67,4 +67,20 @@ describe 'Plextail' do
67
67
  yielded_file.should == File.join(directory, 'data.log')
68
68
  yielded_line.should == 'stuff'
69
69
  end
70
+
71
+ it "reads from piped-in input if no path is supplied" do
72
+ stub_const 'ARGF', `tail #{directory}/*.log`
73
+
74
+ yielded_file, yielded_line = nil, nil
75
+
76
+ Plextail.track do |line|
77
+ yielded_file, yielded_line = line.file, line.raw
78
+
79
+ line.token = 'token'
80
+ line.process_id = 'spec'
81
+ end
82
+
83
+ yielded_file.should == File.join(directory, 'error.log')
84
+ yielded_line.should == 'nonsense'
85
+ end
70
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plextail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-18 00:00:00.000000000 Z
12
+ date: 2013-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: -273195946337692726
128
+ hash: 3380038206689063187
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements:
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  segments:
136
136
  - 0
137
- hash: -273195946337692726
137
+ hash: 3380038206689063187
138
138
  requirements: []
139
139
  rubyforge_project:
140
140
  rubygems_version: 1.8.23