log_parser 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/log_parser/client.rb +4 -3
- data/lib/log_parser/version.rb +1 -1
- data/test/log_parser/client_test.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 953677b838979552d086b794c76a77d1089ff4e9
|
4
|
+
data.tar.gz: 91097424fb4ca19271f373694ed397f6d05affdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e278f0564dd27bd872fa1683e5f697164a938e853598137a1b1d47ad9a79ed04c610268f59aa4b12ca948b9ee71bfe12706f227d92302e67411c6e3a5a4cfda8
|
7
|
+
data.tar.gz: e17cd306ca5ae5c6db98a3a83a361eb5b4683c06743093bf37b3f5eaab306739ee17fb866859b5580806753c121f8d5e7b9e62bd74a35a7f532255c4061753de
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# LogParser
|
2
2
|
|
3
|
-
|
3
|
+
A simple class for searching through a log
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,8 +18,15 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
The class overs a some methods for scanning through a log `by_message(msg)`, `erors`, `warnings`, `since(datetime)` and `uniq`.
|
22
|
+
These methods can be chained together to refine your search. For example:
|
22
23
|
|
24
|
+
```Ruby
|
25
|
+
log = LogParser::Client.new('some.log')
|
26
|
+
log.errors.by_message('authentication failed').since(1.day.ago)
|
27
|
+
#=> ["[2014-11-13T23:12:14-07:00] ERROR [page_id 95239] Authentication failed with token ..."]
|
28
|
+
```
|
29
|
+
|
23
30
|
## Contributing
|
24
31
|
|
25
32
|
1. Fork it ( https://github.com/[my-github-username]/log_parser/fork )
|
data/lib/log_parser/client.rb
CHANGED
@@ -5,7 +5,7 @@ module LogParser
|
|
5
5
|
#
|
6
6
|
# Filter lines from the log file by chaining methods together:
|
7
7
|
#
|
8
|
-
# log = LogParser::Client.new('
|
8
|
+
# log = LogParser::Client.new('some.log')
|
9
9
|
# log.errors.by_message('authentication failed').since(1.day.ago)
|
10
10
|
# #=> ["[2014-11-13T23:12:14-07:00] ERROR [page_id 95239] Authentication failed with token ..."]
|
11
11
|
#
|
@@ -56,10 +56,11 @@ module LogParser
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def by_message(
|
59
|
+
def by_message(pattern_or_text)
|
60
|
+
pattern = pattern_or_text.is_a?(Regexp) ? pattern_or_text : Regexp.new(pattern_or_text, Regexp::IGNORECASE)
|
60
61
|
chain do |items|
|
61
62
|
for line in lines
|
62
|
-
items << line if line.message =~
|
63
|
+
items << line if line.message =~ pattern
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
data/lib/log_parser/version.rb
CHANGED
@@ -66,4 +66,11 @@ class LogParser::ClientTest < MiniTest::Unit::TestCase
|
|
66
66
|
assert_equal 3, prefixes.count
|
67
67
|
assert_equal ['page_id 24323', 'page_id 75645', 'page_id 95239'], prefixes
|
68
68
|
end
|
69
|
+
|
70
|
+
def test_chaining_methods
|
71
|
+
date = DateTime.parse('2014-11-13T23:12:12-07:00')
|
72
|
+
lines = @log.by_prefix('page_id 24323').by_message(/saved \d+ reviews/i).since(date).uniq
|
73
|
+
assert_equal 1, lines.count
|
74
|
+
assert_equal '[page_id 24323] Saved 10 reviews', lines.first.full_message
|
75
|
+
end
|
69
76
|
end
|