chainsaw 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,25 +55,19 @@ module Chainsaw
55
55
  }
56
56
  }
57
57
 
58
- def self.detect(log)
59
- type = nil
60
-
61
- log.each_line do |line|
62
- type = get_type(line)
63
- break unless type.nil?
64
- end
58
+ def self.detect(line)
59
+ type = get_type(line)
60
+ type.nil? ? nil : Format.new(type, PATTERNS[type])
61
+ end
65
62
 
66
- if type.nil?
67
- puts "\033[31mUnable to determine log format :(\033[0m"
68
- exit
69
- else
70
- Format.new(type, PATTERNS[type])
71
- end
63
+ def self.undetectable!
64
+ puts "\033[31mUnable to determine log format :(\033[0m"
65
+ exit
72
66
  end
73
67
 
74
68
  def self.get_type(line)
75
69
  type = nil
76
-
70
+
77
71
  PATTERNS.each do |key, value|
78
72
  if line.match(value[:pattern])
79
73
  type = key
@@ -15,19 +15,24 @@ module Chainsaw
15
15
  @range = range
16
16
  @options = options
17
17
  @log = File.open(@logfile)
18
- @format = Detector.detect(@log)
19
18
  @line_count = 0
20
19
 
21
- @log.rewind
22
-
23
20
  self
24
21
  end
25
22
 
26
23
  # Start iterating through the log lines and filtering them accordingly.
27
24
  def start
28
- @log.each_line do |line|
29
- filter = @options.filter
30
- match = line.match(@format.pattern)
25
+ @ofilter = @options.filter
26
+
27
+ File.open(@logfile).each do |line|
28
+ if !@detected && @format = Detector.detect(line)
29
+ @detected = true
30
+ @log.rewind
31
+ elsif @format.nil?
32
+ next
33
+ end
34
+
35
+ match = line.match(@format.pattern)
31
36
 
32
37
  if match
33
38
  timestamp = match[1]
@@ -37,7 +42,7 @@ module Chainsaw
37
42
  end
38
43
 
39
44
  # a match was found if we are filtering additional text, check that too
40
- if match && @range.cover?(time) && ( !filter || filter && line.include?(filter) )
45
+ if match && @range.cover?(time) && ( !@ofilter || @ofilter && line.include?(@ofilter) )
41
46
  found(line, timestamp)
42
47
  # a match was found and we are outputting non-timestamped lines
43
48
  elsif match && @outputting
@@ -1,3 +1,3 @@
1
1
  module Chainsaw
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chainsaw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-04 00:00:00.000000000 Z
13
+ date: 2012-10-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: chronic