log-analyzer 0.1.0 → 0.2.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 +25 -0
- data/lib/log-analyzer.rb +9 -0
- data/lib/log-analyzer/cli.rb +1 -1
- data/lib/log-analyzer/command/log-analyzer.rb +8 -1
- data/lib/log-analyzer/config.rb +10 -0
- data/lib/log-analyzer/endpoint.rb +1 -1
- data/lib/log-analyzer/log.rb +6 -3
- data/lib/log-analyzer/routes.rb +6 -3
- data/lib/log-analyzer/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8d3ab240961adfb8a7a8f95f38b19ab967dc88
|
4
|
+
data.tar.gz: c07499a1e0a7001e39cba2d8ccb606e3f066aa9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c070b05e228ea3539d920b4a2bcee2552d96787bc5e9127537860d8d5e3e333860ae82ff4d16bcd97f09427e2d0a33813c70bc198665848b4bc287259c8818fa
|
7
|
+
data.tar.gz: 0549d9c8cd21aaba0df5c722f41e7f9ffdb10c1ee95eeeb3e4ab739f3ce83d65298cdcb4dcf145d86bde5e83cb9c58ea52bda4eb3b47644ae7183612c94ad94c
|
data/README.md
CHANGED
@@ -30,6 +30,31 @@ Other Framework Application:
|
|
30
30
|
|
31
31
|
$ log-analyzer -r routing_file <file ...>
|
32
32
|
|
33
|
+
## CLI Reference
|
34
|
+
|
35
|
+
Help:
|
36
|
+
|
37
|
+
```shell
|
38
|
+
$ log-analyzer --help
|
39
|
+
Usage: log-analyzer [options] <file ...>
|
40
|
+
-h, --help output usage information
|
41
|
+
-V, --version output the version number
|
42
|
+
-r FILE routing format file
|
43
|
+
-R, --route-regexp VALUE route regexp
|
44
|
+
-L, --log-regexp VALUE log regexp
|
45
|
+
```
|
46
|
+
|
47
|
+
Example:
|
48
|
+
|
49
|
+
```shell
|
50
|
+
$ log-analyzer -r path/to/routes.txt path/to/application.log
|
51
|
+
┏━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┓
|
52
|
+
┃ method ┃ endpoint ┃ count ┃
|
53
|
+
┣━━━━━━━━╊━━━━━━━━━━╊━━━━━━━┫
|
54
|
+
┃ GET ┃ / ┃ 1 ┃
|
55
|
+
┗━━━━━━━━┻━━━━━━━━━━┻━━━━━━━┛
|
56
|
+
```
|
57
|
+
|
33
58
|
## Development
|
34
59
|
|
35
60
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/log-analyzer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'log-analyzer/version'
|
2
|
+
require 'log-analyzer/config'
|
2
3
|
require 'log-analyzer/routes'
|
3
4
|
require 'log-analyzer/analyze'
|
4
5
|
require 'log-analyzer/log'
|
@@ -9,5 +10,13 @@ require 'log-analyzer/rails/railtie.rb' if defined?(Rails)
|
|
9
10
|
|
10
11
|
module Log
|
11
12
|
module Analyzer
|
13
|
+
module_function
|
14
|
+
def self.configure(&block)
|
15
|
+
yield(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
@_config ||= Config.new
|
20
|
+
end
|
12
21
|
end
|
13
22
|
end
|
data/lib/log-analyzer/cli.rb
CHANGED
@@ -3,7 +3,7 @@ require 'command_line_reporter'
|
|
3
3
|
module Log::Analyzer
|
4
4
|
class CLI
|
5
5
|
def self.run(files, options)
|
6
|
-
routing_text = File.read(options[:
|
6
|
+
routing_text = File.read(options[:routing_file])
|
7
7
|
analyze = Analyze.new(files, routing_text)
|
8
8
|
Report.new(analyze.sort).run
|
9
9
|
end
|
@@ -18,12 +18,19 @@ op.on('-V', '--version', 'output the version number') do |v|
|
|
18
18
|
exit
|
19
19
|
end
|
20
20
|
|
21
|
-
op.on('-r
|
21
|
+
op.on('-r FILE', 'routing format file') { |v| opts[:routing_file] = v }
|
22
|
+
op.on('-R VALUE', '--route-regexp', 'route regexp') { |v| opts[:route_regexp] = v }
|
23
|
+
op.on('-L VALUE', '--log-regexp', 'log regexp') { |v| opts[:log_regexp] = v }
|
22
24
|
|
23
25
|
op.parse!(ARGV)
|
24
26
|
|
25
27
|
if ARGV.empty?
|
26
28
|
puts op
|
27
29
|
else
|
30
|
+
Log::Analyzer.configure do |config|
|
31
|
+
config.route_regexp = Regexp.new(opts[:route_regexp]) if opts[:route_regexp]
|
32
|
+
config.log_regexp = Regexp.new(opts[:log_regexp]) if opts[:log_regexp]
|
33
|
+
end
|
34
|
+
|
28
35
|
Log::Analyzer::CLI.run(ARGV, opts)
|
29
36
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Log::Analyzer
|
2
|
+
class Config
|
3
|
+
attr_accessor :log_regexp, :route_regexp
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@route_regexp = /(GET|POST|DELETE|PATCH|PUT)\s+([^\s]*)\s/i
|
7
|
+
@log_regexp = /Started (?<request_method>GET|POST|DELETE|PATCH|PUT) "(?<path_info>[^"]+)"/i
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/log-analyzer/log.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
module Log::Analyzer
|
2
2
|
class Log
|
3
|
-
LOG_REGEXP = /Started (?<request_method>GET|POST|DELETE|PATCH|PUT) "(?<path_info>[^"]+)"/i
|
4
|
-
|
5
3
|
def initialize(path)
|
6
4
|
@file = File.open(path)
|
7
5
|
end
|
8
6
|
|
9
7
|
def each_line(&block)
|
10
8
|
@file.each_line do |line|
|
11
|
-
next unless md = line.match(
|
9
|
+
next unless md = line.match(regexp)
|
12
10
|
env = md.names.inject({}) do |hash, name|
|
13
11
|
hash[name.upcase] = md[name]
|
14
12
|
hash
|
@@ -16,5 +14,10 @@ module Log::Analyzer
|
|
16
14
|
block.call(ActionDispatch::Request.new(env))
|
17
15
|
end
|
18
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def regexp
|
20
|
+
::Log::Analyzer.config.log_regexp
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
data/lib/log-analyzer/routes.rb
CHANGED
@@ -3,14 +3,17 @@ require 'action_dispatch'
|
|
3
3
|
|
4
4
|
module Log::Analyzer
|
5
5
|
class Routes < ActionDispatch::Journey::Routes
|
6
|
-
ROUTE_REGEXP = /(GET|POST|DELETE|PATCH|PUT)\s+([^\s]*)\s/i
|
7
|
-
|
8
6
|
def initialize(routes_text)
|
9
7
|
super()
|
10
|
-
routes_text.scan(
|
8
|
+
routes_text.scan(regexp) do |request_method, request_path|
|
11
9
|
path_pattern = Pattern.from_string(request_method, request_path)
|
12
10
|
add_route(nil, path_pattern, {request_method: /^#{request_method}$/}, {}, {})
|
13
11
|
end
|
14
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def regexp
|
16
|
+
::Log::Analyzer.config.route_regexp
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
data/lib/log-analyzer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log-analyzer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shiro16
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/log-analyzer/analyze.rb
|
146
146
|
- lib/log-analyzer/cli.rb
|
147
147
|
- lib/log-analyzer/command/log-analyzer.rb
|
148
|
+
- lib/log-analyzer/config.rb
|
148
149
|
- lib/log-analyzer/endpoint.rb
|
149
150
|
- lib/log-analyzer/log.rb
|
150
151
|
- lib/log-analyzer/pattern.rb
|