mongodb_logger 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/.travis.yml +13 -7
- data/Gemfile +1 -7
- data/README.md +128 -117
- data/Rakefile +11 -40
- data/SUPPORTED_RAILS_VERSIONS +3 -1
- data/app/assets/javascripts/analytics.js.coffee +66 -0
- data/app/assets/javascripts/logs.js.coffee +107 -164
- data/app/assets/javascripts/mongodb_logger.js +11 -2
- data/app/assets/javascripts/vendors/jquery-1.8.3.min.js +2 -0
- data/app/assets/javascripts/vendors/jquery-ui-1.9.2.min.js +6 -0
- data/app/assets/javascripts/vendors/jquery.pjax.min.js +13 -6
- data/app/assets/javascripts/vendors/rickshaw/d3.layout.min.js +1 -0
- data/app/assets/javascripts/vendors/rickshaw/d3.min.js +2 -0
- data/app/assets/javascripts/vendors/rickshaw/rickshaw.js +2637 -0
- data/app/assets/stylesheets/humanity/{jquery-ui-1.8.16.custom.css → jquery-ui-1.9.2.custom.css} +0 -0
- data/app/assets/stylesheets/layout.css +1 -1
- data/app/assets/stylesheets/library.css.erb +2 -2
- data/app/assets/stylesheets/mongodb_logger.css +2 -1
- data/app/assets/stylesheets/rickshaw/rickshaw.css +307 -0
- data/bin/mongodb_logger_web +1 -2
- data/config.ru +8 -1
- data/examples/server_config.yml +1 -2
- data/features/mongodb_logger_web.feature +1 -1
- data/features/step_definitions/mongodb_logger_web_steps.rb +18 -12
- data/lib/mongodb_logger.rb +6 -2
- data/lib/mongodb_logger/adapters.rb +3 -0
- data/lib/mongodb_logger/adapters/base.rb +45 -0
- data/lib/mongodb_logger/adapters/mongo.rb +91 -0
- data/lib/mongodb_logger/adapters/moped.rb +95 -0
- data/lib/mongodb_logger/logger.rb +39 -71
- data/lib/mongodb_logger/replica_set_helper.rb +11 -2
- data/lib/mongodb_logger/server.rb +15 -36
- data/lib/mongodb_logger/server/model/analytic.rb +54 -37
- data/lib/mongodb_logger/server/view_helpers.rb +5 -1
- data/lib/mongodb_logger/server/views/analytics.erb +8 -7
- data/lib/mongodb_logger/server/views/layout.erb +4 -11
- data/lib/mongodb_logger/server/views/overview.erb +6 -6
- data/lib/mongodb_logger/server/views/shared/_collection_stats.erb +4 -4
- data/lib/mongodb_logger/server/views/shared/_dynamic_filter.erb +1 -1
- data/lib/mongodb_logger/server/views/shared/_log_info.erb +1 -1
- data/lib/mongodb_logger/server/views/shared/_tabs.erb +2 -2
- data/lib/mongodb_logger/server/views/shared/_tail_panel.erb +4 -4
- data/lib/mongodb_logger/server/views/shared/_top_panel.erb +1 -1
- data/lib/mongodb_logger/server/views/show_log.erb +11 -1
- data/lib/mongodb_logger/server_config.rb +17 -66
- data/lib/mongodb_logger/version.rb +1 -1
- data/mongodb_logger.gemspec +19 -20
- data/spec/javascripts/MongodbLoggerMainSpec.js +2 -2
- data/spec/javascripts/support/jasmine.yml +5 -5
- data/test/Gemfile_tests +2 -1
- data/test/config/samples/database.yml +3 -1
- data/test/config/samples/database_no_file_logging.yml +3 -1
- data/test/shoulda_macros/log_macros.rb +1 -1
- data/test/test.sh +5 -5
- data/test/test_helper.rb +26 -18
- data/test/unit/mongodb_logger_test.rb +21 -20
- metadata +70 -88
- data/app/assets/javascripts/vendors/jquery-1.7.1.min.js +0 -4
- data/app/assets/javascripts/vendors/jquery-ui-1.8.16.min.js +0 -791
- data/mongodb_logger.java.gemspec +0 -43
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm ruby-1.9.3-
|
1
|
+
rvm ruby-1.9.3-p286@mongodb_logger_gems --create
|
data/.travis.yml
CHANGED
@@ -1,19 +1,25 @@
|
|
1
|
-
before_script:
|
2
|
-
- "sh -e /etc/init.d/xvfb start"
|
3
|
-
script: "sh -c 'export DISPLAY=:99.0 && test/test.sh'"
|
4
1
|
language: ruby
|
2
|
+
before_install:
|
3
|
+
- gem install bundler --pre
|
4
|
+
- "export DISPLAY=:99.0"
|
5
|
+
- "sh -e /etc/init.d/xvfb start"
|
6
|
+
script: "sh -c 'test/test.sh'"
|
5
7
|
services:
|
6
8
|
- mongodb
|
7
9
|
rvm:
|
8
10
|
- 1.9.2
|
9
11
|
- 1.9.3
|
10
|
-
|
11
|
-
|
12
|
+
- jruby-19mode
|
13
|
+
- ruby-head
|
14
|
+
- jruby-head
|
12
15
|
notifications:
|
13
16
|
email: false
|
14
17
|
branches:
|
15
18
|
only:
|
16
19
|
- master
|
17
20
|
- development
|
18
|
-
-
|
19
|
-
|
21
|
+
- adapters
|
22
|
+
matrix:
|
23
|
+
allow_failures:
|
24
|
+
- rvm: ruby-head
|
25
|
+
- rvm: jruby-head
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MongodbLogger [![Build Status](https://secure.travis-ci.org/le0pard/mongodb_logger.png)](http://travis-ci.org/le0pard/mongodb_logger)
|
1
|
+
# MongodbLogger [![Build Status](https://secure.travis-ci.org/le0pard/mongodb_logger.png)](http://travis-ci.org/le0pard/mongodb_logger)
|
2
2
|
|
3
3
|
MongodbLogger is a alternative logger for Rails 3, which log all requests of you application into MongoDB database.
|
4
4
|
It:
|
@@ -20,6 +20,15 @@ For rails 3.0.x latest version 0.2.8.
|
|
20
20
|
|
21
21
|
gem "mongodb_logger"
|
22
22
|
|
23
|
+
1. Add adapter in Gemfile. Supported mongo and moped (mongoid). For example:
|
24
|
+
|
25
|
+
gem "mongo"
|
26
|
+
gem "bson_ext"
|
27
|
+
|
28
|
+
or
|
29
|
+
|
30
|
+
gem "moped"
|
31
|
+
|
23
32
|
1. Add the following line to your ApplicationController:
|
24
33
|
|
25
34
|
include MongodbLogger::Base
|
@@ -36,19 +45,21 @@ For rails 3.0.x latest version 0.2.8.
|
|
36
45
|
database.yml:
|
37
46
|
|
38
47
|
development:
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
adapter: postgresql
|
49
|
+
database: my_app_development
|
50
|
+
username: postgres
|
51
|
+
mongodb_logger:
|
52
|
+
database: my_app # required (the only required setting)
|
53
|
+
capsize: <%= 10.megabytes %> # default: 250MB
|
54
|
+
host: localhost # default: localhost
|
55
|
+
port: 27017 # default: 27017
|
56
|
+
replica_set: true # default: false - Adds retries for ConnectionFailure during voting for replica set master
|
57
|
+
write_options: # default: {w: 0, wtimeout: 200} - write options for inserts (w - wait for insert to propagate to "w" numbers of nodes)
|
58
|
+
w: 0
|
59
|
+
wtimeout: 200
|
60
|
+
application_name: my_app # default: Rails.application
|
61
|
+
disable_file_logging: false # default: false - disable logging into filesystem (only in MongoDB)
|
62
|
+
collection: some_name # default: Rails.env + "_log" - name of MongoDB collection
|
52
63
|
|
53
64
|
mongodb\_logger.yml:
|
54
65
|
|
@@ -83,162 +94,162 @@ For rails 3.0.x latest version 0.2.8.
|
|
83
94
|
|
84
95
|
rake mongodb_logger:assets:compile[public/assets]
|
85
96
|
|
97
|
+
## Assets pipeline
|
98
|
+
|
86
99
|
For capistrano possible compile assets by receipt. Add this to config/deploy.rb:
|
87
100
|
|
88
|
-
|
89
|
-
|
90
|
-
|
101
|
+
require 'mongodb_logger/capistrano'
|
102
|
+
set :mongodb_logger_assets_dir, "public/assets" # where to put mongodb assets
|
103
|
+
after 'deploy:update_code', 'mongodb_logger:precompile'
|
91
104
|
|
92
105
|
Also you can serve assets from rails app. You need just mount it separately:
|
93
106
|
|
94
|
-
|
95
|
-
|
107
|
+
mount MongodbLogger::Server.new, :at => "/mongodb", :as => :mongodb
|
108
|
+
mount MongodbLogger::Assets.instance, :at => "/mongodb/assets", :as => :mongodb_assets # assets
|
96
109
|
|
97
110
|
|
98
111
|
## Usage
|
99
112
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
113
|
+
After success instalation of gem, a new MongoDB document (record) will be created for each request on your application,
|
114
|
+
by default will record the following information: Runtime, IP Address, Request Time, Controller, Method,
|
115
|
+
Action, Params, Application Name and All messages sent to the logger. The structure of the MongoDB document looks like this:
|
116
|
+
|
117
|
+
{
|
118
|
+
'action' : action_name,
|
119
|
+
'application_name' : application_name (rails root),
|
120
|
+
'controller' : controller_name,
|
121
|
+
'ip' : ip_address,
|
122
|
+
'messages' : {
|
123
|
+
'info' : [ ],
|
124
|
+
'debug' : [ ],
|
125
|
+
'error' : [ ],
|
126
|
+
'warn' : [ ],
|
127
|
+
'fatal' : [ ]
|
128
|
+
},
|
129
|
+
'params' : { },
|
130
|
+
'path' : path,
|
131
|
+
'request_time' : date_of_request,
|
132
|
+
'runtime' : elapsed_execution_time_in_milliseconds,
|
133
|
+
'url' : full_url,
|
134
|
+
'method' : request method (GET, POST, OPTIONS),
|
135
|
+
'session' : information from session,
|
136
|
+
'is_exception' : true only for exceptions (in other cases this field miss)
|
137
|
+
}
|
138
|
+
|
139
|
+
Beyond that, if you want to add extra information to the base of the document (let's say something like user\_id on every request that it's available),
|
140
|
+
you can just call the Rails.logger.add\_metadata method on your logger like so (for example from a before\_filter):
|
141
|
+
|
142
|
+
# make sure we're using the MongodbLogger in this environment
|
143
|
+
Rails.logger.add_metadata(:user_id => @current_user.id) if Rails.logger.respond_to?(:add_metadata)
|
132
144
|
|
133
145
|
## Callback on exceptions
|
134
146
|
|
135
|
-
|
136
|
-
|
147
|
+
For send email or do something on exception you can add callback:
|
148
|
+
|
137
149
|
MongodbLogger::Base.configure do |config|
|
138
150
|
config.on_log_exception do |mongo_record|
|
139
151
|
# do something with this data, for example - send email (better - by background job)
|
140
152
|
end
|
141
153
|
end
|
142
|
-
|
143
|
-
|
154
|
+
|
155
|
+
In this callback send record without "\_id", because logger not wait for insert response from MongoDB.
|
144
156
|
|
145
157
|
## The Front End
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
require 'mongodb_logger/server' # required
|
151
|
-
# this secure you web interface by basic auth, but you can skip this, if you no need this
|
152
|
-
MongodbLogger::Server.use Rack::Auth::Basic do |username, password|
|
153
|
-
[username, password] == ['admin', 'password']
|
154
|
-
end
|
155
|
-
|
156
|
-
and just mount MongodbLogger::Server in rails routes:
|
157
|
-
|
158
|
-
File: you\_rails\_app/config/routes.rb
|
159
|
-
|
160
|
-
mount MongodbLogger::Server.new, :at => "/mongodb"
|
161
|
-
|
162
|
-
Now you can see web interface by url "http://localhost:3000/mongodb"
|
163
|
-
|
164
|
-
If you've installed MongodbLogger as a gem and want running the front end without Rails application, you can do it by this command:
|
165
|
-
|
166
|
-
mongodb_logger_web config.yml
|
158
|
+
|
159
|
+
To setup web interface in you Rails application, first of all create autoload file in you Rails application
|
160
|
+
|
161
|
+
File: you\_rails\_app/config/initializers/mongodb\_logger.rb (example)
|
167
162
|
|
168
|
-
|
163
|
+
require 'mongodb_logger/server' # required
|
164
|
+
# this secure you web interface by basic auth, but you can skip this, if you no need this
|
165
|
+
MongodbLogger::Server.use Rack::Auth::Basic do |username, password|
|
166
|
+
[username, password] == ['admin', 'password']
|
167
|
+
end
|
168
|
+
|
169
|
+
and just mount MongodbLogger::Server in rails routes:
|
170
|
+
|
171
|
+
File: you\_rails\_app/config/routes.rb
|
169
172
|
|
170
|
-
|
171
|
-
host: localhost
|
172
|
-
port: 27017
|
173
|
-
collection: development_log # set for see development logs
|
173
|
+
mount MongodbLogger::Server.new, :at => "/mongodb"
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
175
|
+
Now you can see web interface by url "http://localhost:3000/mongodb"
|
176
|
+
|
177
|
+
If you've installed MongodbLogger as a gem and want running the front end without Rails application, you can do it by this command:
|
178
|
+
|
179
|
+
mongodb_logger_web config.yml
|
180
|
+
|
181
|
+
where config.yml is config, similar to config of Rails apps, but without Rails.env. Example:
|
182
|
+
|
183
|
+
database: app_logs_dev
|
184
|
+
host: localhost
|
185
|
+
port: 27017
|
186
|
+
collection: development_log # set for see development logs
|
187
|
+
|
188
|
+
parameter "collection" should be set, if your set custom for your Rails application or start this front end not for production
|
189
|
+
enviroment (by default taken "production\_log" collection, in Rails application gem generate "#{Rails.env}\_log" collection,
|
190
|
+
if it is not defined in config).
|
191
|
+
|
192
|
+
It's a thin layer around rackup so it's configurable as well:
|
193
|
+
|
194
|
+
mongodb_logger_web config.yml -p 8282
|
182
195
|
|
183
196
|
### Passenger, Unicorn, Thin, etc.
|
184
197
|
|
185
|
-
|
198
|
+
Using Passenger, Unicorn, Thin, etc? MongodbLogger ships with a `config.ru` you can use. See guide:
|
186
199
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
200
|
+
* Passenger Apache: <http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_rack_based_ruby_application>
|
201
|
+
* Passenger Nginx: <http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_a_rack_app>
|
202
|
+
* Unicorn: <http://unicorn.bogomips.org>
|
203
|
+
* Thin: <http://code.macournoyer.com/thin/usage>
|
204
|
+
|
205
|
+
Don't forget setup MONGODBLOGGERCONFIG env variable, which provide information about MongodbLogger config. Example starting with unicorn:
|
206
|
+
|
207
|
+
MONGODBLOGGERCONFIG=examples/server_config.yml unicorn
|
195
208
|
|
196
209
|
## Demo Application with MongodbLogger
|
197
210
|
|
198
|
-
|
211
|
+
Demo: [http://demo-mongodb-logger.catware.org/](http://demo-mongodb-logger.catware.org/)
|
199
212
|
|
200
|
-
|
213
|
+
Demo Sources: [https://github.com/le0pard/mongodb_logger_example_heroku](https://github.com/le0pard/mongodb_logger_example_heroku)
|
201
214
|
|
202
215
|
|
203
216
|
## Querying via the Rails console
|
204
217
|
|
205
218
|
And now, for a couple quick examples on getting ahold of this log data...
|
206
219
|
First, here's how to get a handle on the MongoDB from within a Rails console:
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
=> #<Mongo::Collection:0x007fdc7a4d12b0 @name="development_log" .. >
|
220
|
+
|
221
|
+
>> db = Rails.logger.mongo_adapter.connection
|
222
|
+
=> #<Mongo::DB:0x007fdc7c65adc8 @name="monkey_logs_dev" ... >
|
223
|
+
>> collection = Rails.logger.mongo_adapter.collection
|
224
|
+
=> #<Mongo::Collection:0x007fdc7a4d12b0 @name="development_log" .. >
|
213
225
|
|
214
226
|
Once you've got the collection, you can find all requests for a specific user (with id):
|
215
227
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
228
|
+
>> cursor = collection.find(:user_id => '12355')
|
229
|
+
=> #<Mongo::Cursor:0x1031a3e30 ... >
|
230
|
+
>> cursor.count
|
231
|
+
=> 5
|
220
232
|
|
221
233
|
Find all requests that took more that one second to complete:
|
222
234
|
|
223
|
-
|
224
|
-
|
235
|
+
>> collection.find({:runtime => {'$gt' => 1000}}).count
|
236
|
+
=> 3
|
225
237
|
|
226
238
|
Find all order#show requests with a particular order id (id=order\_id):
|
227
239
|
|
228
|
-
|
240
|
+
>> collection.find({"controller" => "order", "action"=> "show", "params.id" => order_id})
|
229
241
|
|
230
242
|
Find all requests with an exception that contains "RoutingError" in the message or stack trace:
|
231
243
|
|
232
|
-
|
244
|
+
>> collection.find({"messages.error" => /RoutingError/})
|
233
245
|
|
234
246
|
Find all requests with errors:
|
235
247
|
|
236
|
-
|
248
|
+
>> collection.find({"is_exception" => true})
|
237
249
|
|
238
250
|
Find all requests with a request\_date greater than '11/18/2010 22:59:52 GMT'
|
239
251
|
|
240
|
-
|
252
|
+
>> collection.find({:request_time => {'$gt' => Time.utc(2010, 11, 18, 22, 59, 52)}})
|
253
|
+
|
241
254
|
|
242
|
-
|
243
|
-
|
244
255
|
Copyright (c) 2009-2012 Phil Burrows, CustomInk (based on https://github.com/customink/central_logger) and Leopard released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,43 +1,14 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
Bundler.require
|
2
6
|
require 'rake'
|
3
7
|
require 'rake/testtask'
|
4
|
-
|
5
|
-
|
6
|
-
rescue LoadError
|
7
|
-
$stderr.puts "Please install cucumber: `gem install cucumber`"
|
8
|
-
exit 1
|
9
|
-
end
|
10
|
-
|
11
|
-
#require "bundler/gem_tasks"
|
12
|
-
require 'bundler/gem_helper'
|
13
|
-
Bundler::GemHelper.install_tasks(:name => 'mongodb_logger')
|
14
|
-
Bundler::GemHelper.install_tasks(:name => 'mongodb_logger.java')
|
8
|
+
require 'cucumber'
|
9
|
+
require 'cucumber/rake/task'
|
15
10
|
|
16
|
-
|
17
|
-
### Help tasks
|
18
|
-
#########################################
|
19
|
-
|
20
|
-
require 'coffee-script'
|
21
|
-
require 'uglifier'
|
22
|
-
namespace :js do
|
23
|
-
desc "compile coffee-scripts from ./lib/mongodb_logger/server/coffee to ./lib/mongodb_logger/server/public/javascripts"
|
24
|
-
task :compile do
|
25
|
-
source = "#{File.dirname(__FILE__)}/lib/mongodb_logger/server/coffee/"
|
26
|
-
javascripts = "#{File.dirname(__FILE__)}/lib/mongodb_logger/server/public/javascripts/"
|
27
|
-
|
28
|
-
Dir.foreach(source) do |cf|
|
29
|
-
unless cf == '.' || cf == '..'
|
30
|
-
js_compiled = CoffeeScript.compile File.read("#{source}#{cf}")
|
31
|
-
js = Uglifier.compile js_compiled
|
32
|
-
open "#{javascripts}#{cf.gsub('.coffee', '.js')}", 'w' do |f|
|
33
|
-
f.puts js
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
puts "All done."
|
39
|
-
end
|
40
|
-
end
|
11
|
+
require "bundler/gem_tasks"
|
41
12
|
|
42
13
|
#########################################
|
43
14
|
### TESTS
|
@@ -77,17 +48,17 @@ LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
|
|
77
48
|
if ENV['CI']
|
78
49
|
# for ci testing only major rails versions
|
79
50
|
if 'java' == RUBY_PLATFORM
|
80
|
-
RAILS_VERSIONS = ['3.1.6', '3.2.
|
51
|
+
RAILS_VERSIONS = ['3.1.6', '3.2.9']
|
81
52
|
else
|
82
|
-
RAILS_VERSIONS = ['3.1.6', '3.2.
|
53
|
+
RAILS_VERSIONS = ['3.1.6', '3.2.9']
|
83
54
|
end
|
84
55
|
else
|
85
56
|
RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
|
86
57
|
end
|
87
58
|
|
88
59
|
|
89
|
-
LOCAL_GEMS = [['sqlite3', nil], ['shoulda', nil], ["rspec", nil], ["mocha", nil], ["cucumber", nil], ["bundler", "1.0.21"]] +
|
90
|
-
|
60
|
+
LOCAL_GEMS = [['sqlite3', nil], ['shoulda', nil], ["rspec", nil], ["mocha", nil], ["cucumber", nil], ["bundler", "1.0.21"]] +
|
61
|
+
RAILS_VERSIONS.collect { |version| ['rails', version] }
|
91
62
|
|
92
63
|
desc "Vendor test gems: Run this once to prepare your test environment"
|
93
64
|
task :vendor_test_gems do
|