sherlog-holmes 0.5.3 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89fef16d03fd77144d784c604993bf7d2a8f18b6
4
- data.tar.gz: c7a26a20842726588da1898cac1a1ef5cb3eb151
3
+ metadata.gz: d61f55e471efe178f7516eca3d2cb2429c2ea9ec
4
+ data.tar.gz: 3f44b1dae8ac75317569c9e96bcd6a91cf16aef0
5
5
  SHA512:
6
- metadata.gz: e4ce46bf65225a0693cae3fc309b256a4b0ba9c2871dc32d0ee2f32c98cdc6eb21610ee9b09f0e51ffeb4a3d5ba78466301fbae76b2084a4e441986bb91281ff
7
- data.tar.gz: 1c7c4de2ede9ea31acd80147359daf37adee66b5c29fa4704f558b5110b9e2379b09fc1168ee6449c98962dc7c41f622a622447bb5739a3095d6b20fe9ccfb6c
6
+ metadata.gz: 199e7823b3563bf9e2ee6e83b251c39ee534be0208a49601ddb528197297a0ab4fb799bae8a97afe54ebb8374726a51e6d7b0e1fb1c09547fd1fee3798fe3759
7
+ data.tar.gz: cce1db2a4804194bccdd16963374f5023e045165b8eb5cdc74d5229961169bdca3d09098eee44e081fa91a810abb4c2a11b3ae6a030586c9927f23868ab306a7
data/README.md CHANGED
@@ -159,6 +159,10 @@ $ sherlog --level ERROR --print crazy-log-file.log > sane-log-file.log
159
159
 
160
160
  This will instruct Sherlog to not print stacktraces for entries. This only has effect if used with `--print`.
161
161
 
162
+ `--max N`
163
+
164
+ This will process only the first `N` filtered entries.
165
+
162
166
  `--count GROUPS...`
163
167
 
164
168
  Set this and Sherlog will count the number of entries per level, category, origin or exception. The possible parameters are (separated by a `,`):
data/bin/sherlog CHANGED
@@ -124,6 +124,10 @@ end
124
124
 
125
125
  @opts.separator "\n Operation Options\n".bold.white
126
126
 
127
+ @opts.on '--max N', 'Filters only the first N occurrences' do |max|
128
+ @listeners[:occurrences] = OccurrenceListener::new max
129
+ end
130
+
127
131
  @opts.on '--print', 'Prints the filtered entries' do
128
132
  @listeners[:print] = PrintListener::new
129
133
  end
data/changelog.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.6.0
4
+
5
+ - Added the occurrence listener (`--max` option)
6
+
3
7
  ## v0.5.3
4
8
 
5
9
  - Added JBoss AS log patterns
@@ -30,6 +30,7 @@ require_relative 'sherlog_holmes/filter'
30
30
  require_relative 'sherlog_holmes/parser'
31
31
  require_relative 'sherlog_holmes/listeners/print_listener'
32
32
  require_relative 'sherlog_holmes/listeners/count_listener'
33
+ require_relative 'sherlog_holmes/listeners/occurrence_listener'
33
34
 
34
35
  module Sherlog
35
36
 
@@ -23,10 +23,11 @@
23
23
  module Sherlog
24
24
  class Entry
25
25
 
26
- attr_accessor :time, :level, :category, :origin, :message, :exceptions, :stacktrace, :raw_content
26
+ attr_accessor :process, :time, :level, :category, :origin, :message, :exceptions, :stacktrace, :raw_content
27
27
 
28
28
  def initialize(params = {})
29
29
  params = params.dup
30
+ @process = ParserProcess::new
30
31
  @time = params.delete :time if params[:time]
31
32
  @level = params.delete :level if params[:level]
32
33
  @category = params.delete :category if params[:category]
@@ -0,0 +1,39 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2015 Marcelo "Ataxexe" Guimarães <ataxexe@devnull.tools>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Sherlog
24
+
25
+ class OccurrenceListener
26
+
27
+ def initialize(max_occurrences)
28
+ @max = max_occurrences.to_i
29
+ @count = 0
30
+ end
31
+
32
+ def call(entry)
33
+ @count += 1
34
+ entry.process.stop if @count >= @max
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require_relative 'entry'
24
+
23
25
  module Sherlog
24
26
  class Parser
25
27
 
@@ -57,6 +59,7 @@ module Sherlog
57
59
 
58
60
  def parse(input)
59
61
  entry = nil
62
+ process = ParserProcess::new
60
63
  foreach input do |line|
61
64
  try_guess_pattern line unless @patterns[:entry]
62
65
  if @patterns[:entry] =~ line
@@ -64,6 +67,7 @@ module Sherlog
64
67
  # notify the last entry parsed
65
68
  notify entry if entry and @filter.accept? entry
66
69
  entry = Entry::new entry_data
70
+ entry.process = process
67
71
  entry.raw_content = line.chomp
68
72
  entry.exceptions << Regexp.last_match[:exception] if @patterns[:exception] =~ entry.message
69
73
  else
@@ -77,6 +81,7 @@ module Sherlog
77
81
  entry.raw_content << $/ << line.chomp
78
82
  end
79
83
  end
84
+ break if process.stop_requested?
80
85
  end
81
86
  # notify the last entry parsed
82
87
  notify entry if entry and @filter.accept? entry
@@ -93,7 +98,7 @@ module Sherlog
93
98
  end
94
99
 
95
100
  def notify(entry)
96
- return unless entry
101
+ return if entry.process.stop_requested?
97
102
  @listeners.each do |listener|
98
103
  listener.call entry
99
104
  end
@@ -107,4 +112,16 @@ module Sherlog
107
112
  end
108
113
 
109
114
  end
115
+
116
+ class ParserProcess
117
+
118
+ def stop
119
+ @request_stop = true
120
+ end
121
+
122
+ def stop_requested?
123
+ @request_stop
124
+ end
125
+
126
+ end
110
127
  end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Sherlog
24
- VERSION = '0.5.3'
24
+ VERSION = '0.6.0'
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sherlog-holmes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ataxexe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-20 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yummi
@@ -99,6 +99,7 @@ files:
99
99
  - lib/sherlog_holmes/entry.rb
100
100
  - lib/sherlog_holmes/filter.rb
101
101
  - lib/sherlog_holmes/listeners/count_listener.rb
102
+ - lib/sherlog_holmes/listeners/occurrence_listener.rb
102
103
  - lib/sherlog_holmes/listeners/print_listener.rb
103
104
  - lib/sherlog_holmes/parser.rb
104
105
  - lib/sherlog_holmes/result.rb