rack-http-logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +18 -0
- data/LICENSE +19 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/lib/rack/http-logger.rb +45 -0
- data/rack-http-logger-0.0.1.gem +0 -0
- data/rack-http-logger.gemspec +23 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 642e14eefadc39818c60f0a90a509d19ef658b14
|
4
|
+
data.tar.gz: b716b5ea8311d70c64ff05687f3698f7ff8dac59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a28ea9211e98c4224641f02da06cae9ed9eacfd494dc95e761908229690046fb8f590a51f772abb934a24c2a6a89ac9aaa546862c167c12e64ff04d8165c7bf1
|
7
|
+
data.tar.gz: 1bf1c05284c5241642b7d16646bb775b84c1333d8182bc33a5234246ccb7acd32147e91203f3afa4471b011b2cae60363ac21abc42b62de1b2d688fa29517a5e
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Mattt Thompson (http://mattt.me/)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Rack::HTTPLogger
|
2
|
+
|
3
|
+
`Rack::HTTPLogger` is Rack middleware that provides a logging endpoint for your application. HTTP request parameters are automatically formatted according to [l2met](https://github.com/ryandotsmith/l2met) and logged to a specified stream, such as `STDOUT`.
|
4
|
+
|
5
|
+
This is designed for anyone using Heroku, which uses [Logplex](https://devcenter.heroku.com/articles/logplex) to aggregate messages for further monitoring and analytics. With `Rack::HTTPLogger` remote events such as mobile device registrations can be collected and processed into your common log stream.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install rack-http-logger
|
11
|
+
```
|
12
|
+
|
13
|
+
## Options
|
14
|
+
|
15
|
+
- `stream`: Stream to which lines are logged. _Defaults to `$stdout`_.
|
16
|
+
- `sync`: Print log lines to stream synchronously (not recommended for applications with high throughput). _Defaults to `true`_
|
17
|
+
- `method`: Matched HTTP Method. _Defaults to `LOG`_
|
18
|
+
- `path`: Matched URL path. _Defaults to `/`_
|
19
|
+
- `source`: Source attribute in log line. _Defaults to `rack-http-logger`_
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Rack::HTTPLogger can be run as Rack middleware.
|
24
|
+
|
25
|
+
### config.ru
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'rack/http-logger'
|
29
|
+
|
30
|
+
use Rack::HTTPLogger
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contact
|
34
|
+
|
35
|
+
Mattt Thompson
|
36
|
+
|
37
|
+
- http://github.com/mattt
|
38
|
+
- http://twitter.com/mattt
|
39
|
+
- m@mattt.me
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
Rack::HTTPLogger is available under the MIT license. See the LICENSE file for more info.
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
gemspec = eval(File.read("rack-http-logger.gemspec"))
|
5
|
+
|
6
|
+
task :build => "#{gemspec.full_name}.gem"
|
7
|
+
|
8
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ["rack-http-logger.gemspec"] do
|
9
|
+
system "gem build rack-http-logger.gemspec"
|
10
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Rack #:nodoc:
|
2
|
+
class HTTPLogger
|
3
|
+
VERSION = '0.1.0'
|
4
|
+
|
5
|
+
def initialize(app, options = {})
|
6
|
+
@app = app
|
7
|
+
|
8
|
+
@stream = options[:stream] || $stdout
|
9
|
+
@stream.sync = true unless options.fetch(:sync, true)
|
10
|
+
@source = options[:source] || "rack-http-logger"
|
11
|
+
|
12
|
+
@method = options[:method] ? "#{options[:method]}".upcase : "LOG"
|
13
|
+
@path = options[:path] || "/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
return @app.call(env) unless env["REQUEST_METHOD"] == @method and env["REQUEST_PATH"] == @path
|
18
|
+
|
19
|
+
request = Rack::Request.new(env)
|
20
|
+
|
21
|
+
if request.media_type == "application/json" and (body = env[POST_BODY].read).length.nonzero?
|
22
|
+
log JSON.parse(body)
|
23
|
+
else
|
24
|
+
log request.params
|
25
|
+
end
|
26
|
+
|
27
|
+
[201, {"Content-Type" => "text/plain"}, []]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def log(parameters)
|
33
|
+
return if parameters.nil? or parameters.empty?
|
34
|
+
|
35
|
+
measures = flatten(parameters).collect{|keys, value| "#{keys.collect(&:to_s).join('.')}=#{value}"}
|
36
|
+
|
37
|
+
@stream.puts ["source=#{@source}", *measures].join(" ")
|
38
|
+
end
|
39
|
+
|
40
|
+
def flatten(hash, k = [])
|
41
|
+
return {Array(k) => hash} unless hash.is_a?(Hash)
|
42
|
+
hash.inject({}){ |h, v| h.merge! flatten(v[-1], k + [v[0]]) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack/http-logger"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack-http-logger"
|
7
|
+
s.authors = ["Mattt Thompson"]
|
8
|
+
s.email = "m@mattt.me"
|
9
|
+
s.homepage = "http://mattt.me"
|
10
|
+
s.version = Rack::HTTPLogger::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.summary = "Rack::HTTPLogger"
|
13
|
+
s.description = "Log arbitrary metrics from HTTP request parameters according to l2met conventions."
|
14
|
+
|
15
|
+
s.add_dependency "rack", "~> 1.5"
|
16
|
+
|
17
|
+
s.add_development_dependency "rake"
|
18
|
+
|
19
|
+
s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|example|log|pkg|script|spec|test|vendor)/ }
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-http-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mattt Thompson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Log arbitrary metrics from HTTP request parameters according to l2met
|
42
|
+
conventions.
|
43
|
+
email: m@mattt.me
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ./Gemfile
|
49
|
+
- ./Gemfile.lock
|
50
|
+
- ./lib/rack/http-logger.rb
|
51
|
+
- ./LICENSE
|
52
|
+
- ./rack-http-logger-0.0.1.gem
|
53
|
+
- ./rack-http-logger.gemspec
|
54
|
+
- ./Rakefile
|
55
|
+
- ./README.md
|
56
|
+
homepage: http://mattt.me
|
57
|
+
licenses: []
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Rack::HTTPLogger
|
79
|
+
test_files: []
|