log_parser 1.1.1 → 1.2.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: 15d8092dcda167e20e2f888d595cebf939a798f3
4
- data.tar.gz: 2455005caffdbc22c87d4fa731e2d3c8fc83f334
3
+ metadata.gz: 4e6ed6152d28bdb338838f6078a5ed7105c5b1ba
4
+ data.tar.gz: f78aae5d1523cab74c71f32f93613969c85d7a3f
5
5
  SHA512:
6
- metadata.gz: 5a660f32b464dfbfbedafb7ae46ef653e6ced5ddae98dc5a4ac34453fc5cc18a184b59e9c2cf73c474827438418c479d758659a9773e73ae9e92de986acab13e
7
- data.tar.gz: 07b79c5fba09c5ce41c3d00c380a8275583cf683172e9fa6f617cc178d2654ee49e4a4f8ca495e285f1a25f5ae9feab33db1383bce450c7fb399c0646f7a4dfd
6
+ metadata.gz: a86dd4b98c7a3fb9657e337b1c4cd0a73dc1a3a4f2950a8ff4fad7b6c7b176d00e39a0cec600d9330327a7dd263e06bfdd63173e831d652fbf6fa1cd9556ae05
7
+ data.tar.gz: d5494314a5c36b526f970f01d27369f8fc738c6738d42cec1b369f13b7a378447a384e2ac343df98626320a9e60f1b6dd54ec3a39db4da63365c56d05859315a
@@ -10,26 +10,19 @@ module LogParser
10
10
  # #=> ["[2014-11-13T23:12:14-07:00] ERROR [page_id 95239] Authentication failed with token ..."]
11
11
  #
12
12
 
13
- LINE_PATTERN = %r{
14
- \[(\d+-\d+-\d+T\d+:\d+:\d+-\d+:\d+)\] # timestamp
15
- (\s(\w+):)? # type of message (ERROR, WARNING, INFO)
16
- (\s\[(.+)\])? # prefix (introduced by log.rb)
17
- \s(.+)$ # message body
18
- }x
19
-
20
- attr_reader :file
13
+ attr_accessor :file, :line_pattern
21
14
  attr_writer :lines
22
15
 
23
16
  #
24
17
  # @param [String|Pathname] log name of the file in 'log' directory or a Pathname object
25
18
  # @param [Hash] options optional parameters
26
19
  # @option :line_items is an array of LineItem objects
27
- # @option :pattern a custom pattern to use for matching lines
20
+ # @option :line_pattern a custom pattern to use for matching lines
28
21
  #
29
22
  def initialize(log = '', options = {})
30
23
  @file = log.is_a?(String) ? LogParser.path_for(log) : log
31
24
  @lines = options[:line_items]
32
- @pattern = options.fetch(:pattern, LINE_PATTERN)
25
+ @line_pattern = options.fetch(:line_pattern, LogParser.line_pattern)
33
26
  end
34
27
 
35
28
  #
@@ -137,7 +130,7 @@ module LogParser
137
130
  line = nil
138
131
  begin
139
132
  line = f.gets
140
- line_items << LineItem.new($1, $3, $5, $6) if line =~ @pattern
133
+ line_items << LineItem.new($1, $3, $5, $6) if line =~ line_pattern
141
134
  end while line
142
135
  end
143
136
  line_items
@@ -0,0 +1,5 @@
1
+ module LogParser
2
+ class Configuration
3
+ attr_accessor :line_pattern
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module LogParser
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
data/lib/log_parser.rb CHANGED
@@ -2,11 +2,37 @@ require 'date'
2
2
  require 'pathname'
3
3
 
4
4
  require 'log_parser/version'
5
+ require 'log_parser/configuration'
5
6
  require 'log_parser/line_item'
6
7
  require 'log_parser/client'
7
8
 
8
9
  module LogParser
9
- def self.path_for(file)
10
+ extend self
11
+
12
+ LINE_PATTERN = %r{
13
+ \[(\d+-\d+-\d+T\d+:\d+:\d+-\d+:\d+)\] # timestamp
14
+ (\s(\w+):)? # type of message (ERROR, WARNING, INFO)
15
+ (\s\[(.+)\])? # prefix (introduced by log.rb)
16
+ \s(.+)$ # message body
17
+ }x
18
+
19
+ def path_for(file)
10
20
  Pathname.new(File.join(Dir.pwd, 'log', file))
11
21
  end
22
+
23
+ def configure
24
+ yield config
25
+ end
26
+
27
+ def config
28
+ @config ||= Configuration.new
29
+ end
30
+
31
+ def reset_config
32
+ @config = nil
33
+ end
34
+
35
+ def line_pattern
36
+ config.line_pattern || LINE_PATTERN
37
+ end
12
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - lib/log_parser.rb
54
54
  - lib/log_parser/client.rb
55
+ - lib/log_parser/configuration.rb
55
56
  - lib/log_parser/line_item.rb
56
57
  - lib/log_parser/version.rb
57
58
  - log_parser.gemspec