rack-common_logger-fluent 0.3.0 → 0.4.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/bin/flgrep ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'json'
5
+ require 'time'
6
+
7
+ def main(argv)
8
+ options = {}
9
+ opt = OptionParser.new
10
+ opt.on('-c', '--column=s', 'column name to target') {|v| options[:column] = v }
11
+ opt.on('-v', '--value=s', 'value for filtering') {|v| options[:value] = v }
12
+ opt.on('-d', '--date[=s]', 'filtering by date') {|v| options[:date] = v }
13
+ opt.on('--until[=s]', 'filtering by date until ...') {|v| options[:until] = v }
14
+ opt.on('--since[=s]', 'filtering by date since ...') {|v| options[:since] = v }
15
+ opt.on('-m', '--method=(regexp|gt|lt)', 'regexp (default): match by regexp, gt: greater than, lt: less than') {|v| options[:method] = v }
16
+ opt.on('--mode=(filter|color)', 'filter (default): like grep, color: show colored line when match condition.') {|v| options[:mode] = v }
17
+ opt.parse!(argv)
18
+ if options[:column].nil? or options[:value].nil?
19
+ warn opt.help
20
+ exit(1)
21
+ end
22
+
23
+ options[:method] ||= 'regexp'
24
+ options[:mode] ||= 'filter'
25
+
26
+ regexp = Regexp.compile(options[:value], 'i')
27
+
28
+ date_regexp = options[:date] ? Regexp.compile(options[:date], 'i') : nil
29
+ since_date = options[:since] ? Time.parse(options[:since]) : nil
30
+ until_date = options[:until] ? Time.parse(options[:until]) : nil
31
+
32
+ tab_regexp = /\t/
33
+ while line = STDIN.gets
34
+ line.chomp!
35
+ date, tag, data = line.split(tab_regexp)
36
+ if date_regexp
37
+ next if date !~ date_regexp
38
+ end
39
+ if since_date
40
+ dt = Time.parse(date)
41
+ next if dt < since_date
42
+ end
43
+ if until_date
44
+ dt = Time.parse(date)
45
+ next if dt > until_date
46
+ end
47
+ data = JSON.parse(data)
48
+
49
+ case options[:method]
50
+ when 'regexp'
51
+ show_if_match(line, options) {|options| regexp.match(data[options[:column]].to_s) }
52
+ when 'lt'
53
+ show_if_match(line, options) {|options| data[options[:column]] <= options[:value].to_f }
54
+ when 'gt'
55
+ show_if_match(line, options) {|options| data[options[:column]] >= options[:value].to_f }
56
+ else
57
+ end
58
+ end
59
+ end
60
+
61
+ def show_if_match(line, options, &block)
62
+ if block.call(options)
63
+ if options[:mode] == "color"
64
+ puts "\033[31m#{line}\033[0m"
65
+ else
66
+ puts line
67
+ end
68
+ else
69
+ if options[:mode] == "color"
70
+ puts line
71
+ end
72
+ end
73
+ end
74
+
75
+ main(ARGV)
76
+
77
+ __END__
78
+
79
+ = Example =
80
+
81
+ # show access log that runtime is greater than 0.1
82
+ $ flgrep --column=runtime --value=0.1 --method=gt
83
+
84
+ # show access log that match top page.
85
+ $ flgrep --column=path_info --value='^/$'
86
+
87
+ # color match.
88
+ $ flgrep --column=path_info --value='^/$' --mode=color
89
+
@@ -5,13 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rack-common_logger-fluent"
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Keiji, Yoshimi"]
12
- s.date = "2012-05-12"
12
+ s.date = "2012-06-08"
13
13
  s.description = "rack middleware for writing access log to fluentd. "
14
14
  s.email = "walf443@gmail.com"
15
+ s.executables = ["flgrep"]
15
16
  s.extra_rdoc_files = [
16
17
  "LICENSE.txt",
17
18
  "README.rdoc"
@@ -24,6 +25,7 @@ Gem::Specification.new do |s|
24
25
  "README.rdoc",
25
26
  "Rakefile",
26
27
  "VERSION",
28
+ "bin/flgrep",
27
29
  "lib/rack-common_logger-fluent.rb",
28
30
  "lib/rack/common_logger/fluent.rb",
29
31
  "rack-common_logger-fluent.gemspec",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-common_logger-fluent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-12 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluent-logger
@@ -109,7 +109,8 @@ dependencies:
109
109
  version: 1.8.3
110
110
  description: ! 'rack middleware for writing access log to fluentd. '
111
111
  email: walf443@gmail.com
112
- executables: []
112
+ executables:
113
+ - flgrep
113
114
  extensions: []
114
115
  extra_rdoc_files:
115
116
  - LICENSE.txt
@@ -122,6 +123,7 @@ files:
122
123
  - README.rdoc
123
124
  - Rakefile
124
125
  - VERSION
126
+ - bin/flgrep
125
127
  - lib/rack-common_logger-fluent.rb
126
128
  - lib/rack/common_logger/fluent.rb
127
129
  - rack-common_logger-fluent.gemspec
@@ -142,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
144
  version: '0'
143
145
  segments:
144
146
  - 0
145
- hash: -380975601982097249
147
+ hash: 3298616844027280028
146
148
  required_rubygems_version: !ruby/object:Gem::Requirement
147
149
  none: false
148
150
  requirements: