chainsaw 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chainsaw/detector.rb +8 -14
- data/lib/chainsaw/filter.rb +12 -7
- data/lib/chainsaw/version.rb +1 -1
- metadata +2 -2
data/lib/chainsaw/detector.rb
CHANGED
@@ -55,25 +55,19 @@ module Chainsaw
|
|
55
55
|
}
|
56
56
|
}
|
57
57
|
|
58
|
-
def self.detect(
|
59
|
-
type =
|
60
|
-
|
61
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
data/lib/chainsaw/filter.rb
CHANGED
@@ -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
|
-
@
|
29
|
-
|
30
|
-
|
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) && (
|
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
|
data/lib/chainsaw/version.rb
CHANGED
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.
|
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-
|
13
|
+
date: 2012-10-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: chronic
|