request_log 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ pkg/*
2
2
  *.gem
3
3
  .bundle
4
4
  doc/*
5
+ .rvmrc
@@ -0,0 +1,13 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.1.2 (2011-10-25)
4
+
5
+ * Added explicit sorting by time to Db.filtered_requests method to ensure that the `request_log:print` rake task outputs requests in chronological order.
6
+
7
+ ## 0.1.0
8
+
9
+ * Removed summary field from log data since it only contained redundant data and we want to trim the size of the log.
10
+
11
+ ## 0.0.1
12
+
13
+ * Initial version
@@ -1,16 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- request_log (0.1.1)
4
+ request_log (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.1.2)
10
- mocha (0.9.8)
11
- rake
12
- rack (1.2.1)
13
- rake (0.8.7)
9
+ diff-lcs (1.1.3)
10
+ mocha (0.9.12)
11
+ rack (1.2.4)
14
12
  rspec (2.0.0)
15
13
  rspec-core (= 2.0.0)
16
14
  rspec-expectations (= 2.0.0)
@@ -1,4 +1,4 @@
1
- = Request Log
1
+ # Request Log
2
2
 
3
3
  Request Log is a Rack middleware for logging web requests to MongoDB. Each web request becomes a document in MongoDB
4
4
  with fields like path, method, params, status, time, ip, runtime etc.
@@ -6,6 +6,7 @@ The gem offers support for monitoring the time overhead (usually very small) tha
6
6
  The advantages of logging to MongoDB over logging to a plain text file are huge because of the query
7
7
  capabilities of MongoDB. Here is an example of what a log document can look like:
8
8
 
9
+ ```
9
10
  method: "GET"
10
11
  path: "/"
11
12
  ip: "10.218.1.177"
@@ -13,26 +14,32 @@ capabilities of MongoDB. Here is an example of what a log document can look like
13
14
  params: {"hello_world"=>"1"}
14
15
  status: 200
15
16
  runtime: 0.000303
17
+ ```
16
18
 
17
19
  You can easily customize which fields are stored in the log.
18
20
 
19
- == Installation
21
+ ## Installation
20
22
 
21
23
  Add gem dependencies with appropriate version numbers to your Gemfile (assuming you use Bundler):
22
24
 
25
+ ```
23
26
  gem 'mongo', '~> version known to work'
24
27
  gem 'bson_ext', '~> version known to work'
25
28
  gem 'request_log', '~> version known to work'
29
+ ```
26
30
 
27
31
  Install with:
28
32
 
33
+ ```
29
34
  bundle install
35
+ ```
30
36
 
31
37
  Note that it's up to your application how it wants to connect to MongoDB (if at all) and the suggested
32
38
  mongo and bson_ext gems are just suggestions.
33
39
 
34
40
  Next you need to setup a MongoDB connection. Here is a MongoHQ example that in Rails would belong in config/initializers/request_log.rb:
35
41
 
42
+ ```
36
43
  if ENV['MONGOHQ_URL']
37
44
  require 'uri'
38
45
  require 'mongo'
@@ -40,47 +47,62 @@ Next you need to setup a MongoDB connection. Here is a MongoHQ example that in R
40
47
  connection = Mongo::Connection.from_uri(uri.to_s)
41
48
  RequestLog::Db.mongo_db = connection.db(uri.path.gsub(/^\//, ''))
42
49
  end
50
+ ```
43
51
 
44
52
  MongoDB recommends using capped collections for logging as they have good write performance. Here is an example of how to do log rotation when the size hits 20GB (this step is optional, note that the command may take a while):
45
53
 
54
+ ```
46
55
  RequestLog::Db.mongo_db.create_collection("requests", :capped => true, :size => 20000000000)
56
+ ```
47
57
 
48
58
  Now setup the Middleware in your config.ru file:
49
59
 
60
+ ```
50
61
  use RequestLog::Middleware
62
+ ```
51
63
 
52
64
  Here is an example of how you can customize the middleware:
53
65
 
66
+ ```
54
67
  use RequestLog::Middleware,
55
68
  :logger => lambda { |data| RequestLog::Db.requests.insert(data.attributes.except(:runtime)) },
56
69
  :timeout => 0.5
70
+ ```
57
71
 
58
72
  In order to use the Rake tasks you need to make sure you have the MongoDB connection setup and that you
59
73
  require the tasks in your Rakefile, like this:
60
74
 
75
+ ```
61
76
  require 'request_log'
62
77
  require 'config/initializers/request_log.rb' # The file where you setup the mongo db connection
63
78
  require 'request_log/tasks'
79
+ ```
64
80
 
65
- == Accessing the logs
81
+ ## Accessing the logs
66
82
 
67
83
  You can tail the log like this:
68
84
 
85
+ ```
69
86
  rake request_log:tail
87
+ ```
70
88
 
71
89
  If you want to query the log and print a certain time period you can use request_log:print:
72
90
 
91
+ ```
73
92
  rake request_log:print from="2010-10-28 17:06:08" to="2010-10-28 17:06:10" conditions='status: 200'
93
+ ```
74
94
 
75
95
  If you are using MONGOHQ, remember to set the MONGOHQ_URL environment variable.
76
96
 
77
- == Profiling
97
+ ## Profiling
78
98
 
79
99
  To monitor the time consumption and reliability of the MongoDB logging you can use the RequestLog::Profiler class.
80
100
  It records number of failed and successful loggings, average and maximum logging times etc. To persist the profiling
81
101
  information to MongoDB you can configure the profiler like this:
82
102
 
103
+ ```
83
104
  RequestLog::Profiler.persist_enabled = true
84
105
  RequestLog::Profiler.persist_frequency = 1000 # persist profiling info every 1000 requests
106
+ ```
85
107
 
86
108
  The profiling info will then be written to a table (request_log_profiling) in the MongoDB database.
@@ -1,3 +1,4 @@
1
+ require 'timeout'
1
2
  require 'request_log/version'
2
3
  require 'request_log/db'
3
4
  require 'request_log/data'
@@ -28,7 +28,7 @@ module RequestLog
28
28
  start_time = Time.parse(start_time).utc if start_time.is_a?(String)
29
29
  end_time = Time.parse(end_time).utc if end_time.is_a?(String)
30
30
  time_condition = {"time" => {"$gt" => start_time, "$lt" => end_time}}
31
- requests.find(time_condition.merge(parse_conditions(conditions)))
31
+ requests.find(time_condition.merge(parse_conditions(conditions))).sort([:time, :ascending])
32
32
  end
33
33
 
34
34
  def self.print_requests(start_time, end_time, conditions = {})
@@ -1,3 +1,3 @@
1
1
  module RequestLog
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_log
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
4
+ prerelease:
5
+ version: 0.1.2
10
6
  platform: ruby
11
7
  authors:
12
8
  - Peter Marklund
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-12-03 00:00:00 +01:00
18
- default_executable:
13
+ date: 2011-10-25 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: rspec
@@ -24,10 +19,6 @@ dependencies:
24
19
  requirements:
25
20
  - - "="
26
21
  - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 0
30
- - 0
31
22
  version: 2.0.0
32
23
  type: :development
33
24
  prerelease: false
@@ -39,10 +30,6 @@ dependencies:
39
30
  requirements:
40
31
  - - ~>
41
32
  - !ruby/object:Gem::Version
42
- segments:
43
- - 0
44
- - 9
45
- - 8
46
33
  version: 0.9.8
47
34
  type: :development
48
35
  prerelease: false
@@ -54,10 +41,6 @@ dependencies:
54
41
  requirements:
55
42
  - - ~>
56
43
  - !ruby/object:Gem::Version
57
- segments:
58
- - 1
59
- - 2
60
- - 1
61
44
  version: 1.2.1
62
45
  type: :development
63
46
  prerelease: false
@@ -73,10 +56,10 @@ extra_rdoc_files: []
73
56
 
74
57
  files:
75
58
  - .gitignore
76
- - CHANGELOG
59
+ - CHANGELOG.md
77
60
  - Gemfile
78
61
  - Gemfile.lock
79
- - README.rdoc
62
+ - README.md
80
63
  - Rakefile
81
64
  - lib/request_log.rb
82
65
  - lib/request_log/data.rb
@@ -92,7 +75,6 @@ files:
92
75
  - spec/middleware_spec.rb
93
76
  - spec/profiler_spec.rb
94
77
  - spec/spec_helper.rb
95
- has_rdoc: true
96
78
  homepage: ""
97
79
  licenses: []
98
80
 
@@ -106,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
88
  requirements:
107
89
  - - ">="
108
90
  - !ruby/object:Gem::Version
109
- hash: 206132559
91
+ hash: -1609358148950230624
110
92
  segments:
111
93
  - 0
112
94
  version: "0"
@@ -115,14 +97,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
97
  requirements:
116
98
  - - ">="
117
99
  - !ruby/object:Gem::Version
118
- hash: 206132559
100
+ hash: -1609358148950230624
119
101
  segments:
120
102
  - 0
121
103
  version: "0"
122
104
  requirements: []
123
105
 
124
106
  rubyforge_project: request_log
125
- rubygems_version: 1.3.7
107
+ rubygems_version: 1.8.8
126
108
  signing_key:
127
109
  specification_version: 3
128
110
  summary: Rack middleware for logging web requests to a MongoDB database. Provides a profiler for monitoring logging overhead.
data/CHANGELOG DELETED
@@ -1,7 +0,0 @@
1
- * 0.1.0
2
-
3
- * Removed summary field from log data since it only contained redundant data and we want to trim the size of the log.
4
-
5
- * 0.0.1
6
-
7
- * Initial version