rack-requestash 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'rspec', '~> 2.14'
9
+ gem 'rack-test'
10
+ gem 'sinatra'
11
+ gem 'debugger', :platform => :mri_19
12
+ gem 'debugger-pry', :platform => :mri_19
13
+ gem 'pry'
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 R. Tyler Croy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Rack::Requestash
2
+
3
+ Simple Rack "middleware" for generating [logstash](http://logstash.net/)
4
+ friendly request access logs for any Rack-based application.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'rack-requestash'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install rack-requestash
19
+
20
+ ## Usage
21
+
22
+ Rack::Requestash will monkey-patch the `Rack::CommonLogger` class which
23
+ provides Apache-style access logs. In order to enable in in your application,
24
+ try something like:
25
+
26
+
27
+ require 'rack/requestash'
28
+
29
+ class MyServer < Sinatra::Base
30
+ Rack::Requestash.install
31
+
32
+ get '/' do
33
+ 'Yahtzee!'
34
+ end
35
+ end
36
+
37
+
38
+ You will then get nice, JSON formatted logs:
39
+
40
+
41
+ {"length":"2818","code":"200","version":"HTTP/1.1","method":"GET","duration":0.280802331,"query":"","path":"/","ip":"127.0.0.1","user":null,"timestamp":"2013-08-15T05:49:00Z"}
42
+ {"length":0,"code":"304","version":"HTTP/1.1","method":"GET","duration":0.035969114,"query":"","path":"/javascripts/vendor.js","ip":"127.0.0.1","user":null,"timestamp":"2013-08-15T05:49:00Z"}
43
+ {"length":0,"code":"304","version":"HTTP/1.1","method":"GET","duration":0.069988507,"query":"","path":"/javascripts/i18n/en.js","ip":"127.0.0.1","user":null,"timestamp":"2013-08-15T05:49:00Z"}
44
+
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,49 @@
1
+ require 'rack/commonlogger'
2
+ require 'json'
3
+
4
+ module Rack
5
+ class Requestash
6
+ VERSION = "0.0.1"
7
+
8
+ def initialize(app, options={})
9
+ @app = app
10
+
11
+ install if options[:disable_accesslog].nil?
12
+ end
13
+
14
+ def call(env)
15
+ # Simple pass-through, we don't need to mess with the request
16
+ @app.call(env)
17
+ end
18
+
19
+ # Install the Rack::CommonLogger monkeypatch
20
+ def install
21
+ Rack::CommonLogger.class_eval do
22
+
23
+ alias_method :original_log, :log
24
+
25
+ def log(env, status, header, began_at)
26
+ logger = @logger || env['rack.errors']
27
+
28
+ blob = {
29
+ :length => header['Content-Length'] || 0,
30
+ :code => status.to_s[0 .. 3],
31
+ :version => env['HTTP_VERSION'],
32
+ :method => env['REQUEST_METHOD'],
33
+ :duration => (Time.now - began_at),
34
+ :query => env["QUERY_STRING"],
35
+ :path => env['PATH_INFO'],
36
+ :ip => env['HTTP_X_FORWARDED_FOR'] || env['REMOTE_ADDR'],
37
+ :user => env['REMOTE_USER'],
38
+ :timestamp => Time.now.utc.iso8601
39
+ }
40
+
41
+ if logger
42
+ logger.write(blob.to_json)
43
+ logger.write("\n")
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/requestash'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-requestash"
8
+ spec.version = Rack::Requestash::VERSION
9
+ spec.authors = ["R. Tyler Croy"]
10
+ spec.email = ["rtyler.croy@lookout.com"]
11
+ spec.description = "A simple gem for overwriting outputting JSON formatted access logs from Rack apps"
12
+ spec.summary = "A simple gem for overwriting outputting JSON formatted access logs from Rack apps"
13
+ spec.homepage = "https://github.com/lookout/rack-requestash"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+
23
+ spec.add_dependency 'rack'
24
+ spec.add_dependency 'json'
25
+ end
File without changes
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-requestash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - R. Tyler Croy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rack
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: A simple gem for overwriting outputting JSON formatted access logs from
63
+ Rack apps
64
+ email:
65
+ - rtyler.croy@lookout.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - lib/rack/requestash.rb
76
+ - rack-requestash.gemspec
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/lookout/rack-requestash
79
+ licenses:
80
+ - MIT
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ segments:
92
+ - 0
93
+ hash: 123322180174946479
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ segments:
101
+ - 0
102
+ hash: 123322180174946479
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.25
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A simple gem for overwriting outputting JSON formatted access logs from Rack
109
+ apps
110
+ test_files:
111
+ - spec/spec_helper.rb