rack-log-request 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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-log-request.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class LogRequest
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ require 'mongo'
2
+ module Rack
3
+ class LogRequest
4
+
5
+ ##
6
+ # Intialize the LogRequest Middleware.
7
+ #
8
+ # @params[Rack] app the Rack application
9
+ # @params[Hash] options all options about this middleware
10
+ # @opts[String] mongo_db a Mongo::Database object
11
+ # @opts[String] host the host of your MongoDB database
12
+ # @opts[String] port the port of your MongoDB database
13
+ # @opts[String] database the database of your MongoDB database
14
+ # @opts[String] user the user to access your MongoDB database
15
+ # @opts[String] password the password of your MongoDB user to access database
16
+ #
17
+ def initialize(app, options = {})
18
+ @app = app
19
+ unless options.has_key?(:mongo_db)
20
+ @mongo_connection = Mongo::Connection.new(options[:host], options[:port], :timeout => 5)
21
+ if options.has_key?(:user)
22
+ @mongo_connection.add_auth(options[:database], options[:user], options[:password])
23
+ end
24
+ @mongo_database = @mongo_connection.db(options[:database])
25
+ else
26
+ @mongo_database = options[:mongo_db]
27
+ end
28
+ @mongo_collection = @mongo_database.collection('rack-log-request')
29
+ end
30
+
31
+ def call(env)
32
+ t = Time.now
33
+ re = @app.call(env)
34
+ @mongo_collection.insert({:request => env['REQUEST_URI'],
35
+ :millis => (Time.now - t)*1000})
36
+ return re
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack-log-request/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-log-request"
7
+ s.version = Rack::LogRequest::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Cyril Mougel"]
10
+ s.email = ["cyril.mougel@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Log in mongoDB all request do with their time to generate it}
13
+ s.description = %q{Log in mongoDB all request do with their time to generate it}
14
+
15
+ s.rubyforge_project = "rack-log-request"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-log-request
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Cyril Mougel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-16 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Log in mongoDB all request do with their time to generate it
23
+ email:
24
+ - cyril.mougel@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/rack-log-request.rb
36
+ - lib/rack-log-request/version.rb
37
+ - rack-log-request.gemspec
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: rack-log-request
68
+ rubygems_version: 1.5.2
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Log in mongoDB all request do with their time to generate it
72
+ test_files: []
73
+