log2json 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
data/bin/tail-log.sh CHANGED
@@ -65,9 +65,13 @@ build_tail_args() {
65
65
  fi
66
66
 
67
67
  # at this point, no last position was recorded in the SINCEDB for fpath,
68
- # in this case we'd tail from the end of file.
69
-
70
- TAIL_ARGS[$((i++))]="-n+$(( nlines + 1 ))"
68
+ # in this case we'd tail from the end of file unless the FROM_START env
69
+ # var is set.
70
+ if [ "$FROM_START" ]; then
71
+ TAIL_ARGS[$((i++))]="-n+$FROM_START"
72
+ else
73
+ TAIL_ARGS[$((i++))]="-n+$(( nlines + 1 ))"
74
+ fi
71
75
  # Note: we can't just ask tail to seek to the end here(ie, with -n0) since
72
76
  # then we'd lose track of the line count.
73
77
  # Note: if fpath doesn't exist yet, then the above evaluates to "-n+1", which
data/lib/log2json.rb CHANGED
@@ -3,7 +3,7 @@ require 'grok-pure'
3
3
 
4
4
  module Log2Json
5
5
 
6
- def self.main(filters, opts={})
6
+ def self.main(filters, opts={}, &block)
7
7
  output = opts[:output] || STDOUT
8
8
  spitter = opts[:spitter]
9
9
  if spitter.nil?
@@ -15,15 +15,23 @@ def self.main(filters, opts={})
15
15
  end
16
16
  spitter = ::Log2Json::Spitter.new(STDIN, ENV['type'], config)
17
17
  end
18
+ if block.nil?
19
+ block = proc do |rec|
20
+ if not rec['@timestamp'].nil?
21
+ output.write(rec.to_json() << "\n")
22
+ output.flush()
23
+ # NOTE: Ruby's built-in json module, by default, doesn't output any
24
+ # literal newline characters while serializing. So using
25
+ # newlines as json record separator is fine here.
26
+ end
27
+ end
28
+ end
18
29
  spitter.each_record do |rec|
19
- filters[rec['@type']].each { |f| f.filter(rec) }
20
- if ! rec['@timestamp'].nil?
21
- output.write(rec.to_json() << "\n")
22
- output.flush()
23
- # NOTE: Ruby's built-in json module, by default, doesn't output any
24
- # literal newline characters while serializing. So using
25
- # newlines as json record separator is fine here.
30
+ filters[rec['@type']].each do |f|
31
+ rec = f.filter(rec)
32
+ break if rec.nil?
26
33
  end
34
+ block.call(rec) unless rec.nil?
27
35
  end
28
36
  end
29
37
 
@@ -156,9 +164,7 @@ class GrokFilter
156
164
  # Any '@' key-values configured for this filter will also
157
165
  # be added to the record after merging the captured groups.
158
166
  #
159
- # Return the record at the end if there's a match else return nil.
160
- # If the '@timestamp' attribute is removed from a record then the record will
161
- # be dropped.
167
+ # Return the record at the end.
162
168
  def filter(record)
163
169
  grok, match = @pile.match(record['@message'])
164
170
  if match
@@ -195,13 +201,10 @@ class GrokFilter
195
201
  end
196
202
  (fields['filtered_by'] ||= []) << name
197
203
  if @filter_block
198
- @filter_block.call(record)
199
- else
200
- record
204
+ record = @filter_block.call(record)
201
205
  end
202
- else
203
- nil
204
206
  end
207
+ record
205
208
  end
206
209
  end # end class GrokFilter
207
210
 
data/log2json.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'log2json'
3
- s.version = '0.1.19'
3
+ s.version = '0.1.20'
4
4
  s.summary = "Read, filter and ship logs. ie, poor man's roll-your-own, light-weight logstash replacement."
5
5
  s.description = IO.read(File.join(File.dirname(__FILE__), 'README'))
6
6
  s.authors = ['Jack Kuan']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log2json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
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-10-30 00:00:00.000000000 Z
12
+ date: 2013-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jls-grok