log_parser 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36142163ba2daa7fc0c5696d61ace414bf990c53
4
- data.tar.gz: 7221c22e2e25cf8f7ecf108e0bf69a546440ab85
3
+ metadata.gz: 953677b838979552d086b794c76a77d1089ff4e9
4
+ data.tar.gz: 91097424fb4ca19271f373694ed397f6d05affdb
5
5
  SHA512:
6
- metadata.gz: 0718a695404977a316621a6528859f0ae0359418097bbfa6dd1de2f87a2841961221024efe1dc742aeb064279f492ff10e9744eefeea1be32568c2b0971763b3
7
- data.tar.gz: 18017b6591cfcc422d34a3f52a067adbfcb2d0ec636cf2cb5e58dafc91a194a3d2a19ad74e431e65717ab13e49c8d21df5042cab4d9b9ae298a0765cec3722f3
6
+ metadata.gz: e278f0564dd27bd872fa1683e5f697164a938e853598137a1b1d47ad9a79ed04c610268f59aa4b12ca948b9ee71bfe12706f227d92302e67411c6e3a5a4cfda8
7
+ data.tar.gz: e17cd306ca5ae5c6db98a3a83a361eb5b4683c06743093bf37b3f5eaab306739ee17fb866859b5580806753c121f8d5e7b9e62bd74a35a7f532255c4061753de
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LogParser
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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 )
@@ -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('open_table.log')
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(text)
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 =~ Regexp.new(text, Regexp::IGNORECASE)
63
+ items << line if line.message =~ pattern
63
64
  end
64
65
  end
65
66
  end
@@ -1,3 +1,3 @@
1
1
  module LogParser
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley