mongodb_logger 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/.gitignore +2 -1
  2. data/.rvmrc +1 -1
  3. data/.travis.yml +5 -4
  4. data/Appraisals +9 -0
  5. data/CHANGELOG.md +20 -3
  6. data/README.md +58 -35
  7. data/Rakefile +33 -96
  8. data/app/assets/javascripts/analytics.js.coffee +5 -4
  9. data/app/assets/javascripts/logs.js.coffee +11 -11
  10. data/app/assets/javascripts/mongodb_logger.js +2 -1
  11. data/app/assets/javascripts/vendors/jquery-1.9.1.min.js +5 -0
  12. data/app/assets/javascripts/vendors/jquery.pjax.min.js +15 -13
  13. data/app/assets/javascripts/vendors/mustache.min.js +10 -0
  14. data/app/assets/stylesheets/layout.css +20 -15
  15. data/app/assets/stylesheets/mongodb_logger.css +0 -3
  16. data/bin/mongodb_logger_web +1 -2
  17. data/features/rails.feature +20 -8
  18. data/features/step_definitions/mongodb_logger_web_steps.rb +2 -3
  19. data/features/step_definitions/rails_application_steps.rb +84 -58
  20. data/features/step_definitions/rake_steps.rb +10 -0
  21. data/features/support/aruba.rb +5 -0
  22. data/features/support/env.rb +11 -5
  23. data/features/support/rails.rb +55 -67
  24. data/gemfiles/rails31.gemfile +8 -0
  25. data/gemfiles/rails32.gemfile +8 -0
  26. data/lib/mongodb_logger.rb +10 -3
  27. data/lib/mongodb_logger/adapters/base.rb +5 -1
  28. data/lib/mongodb_logger/adapters/mongo.rb +17 -13
  29. data/lib/mongodb_logger/adapters/moped.rb +17 -11
  30. data/lib/mongodb_logger/capistrano.rb +8 -0
  31. data/lib/mongodb_logger/logger.rb +13 -26
  32. data/lib/mongodb_logger/rack_middleware.rb +24 -0
  33. data/lib/mongodb_logger/railtie.rb +4 -4
  34. data/lib/mongodb_logger/server.rb +43 -68
  35. data/lib/mongodb_logger/server/helpers.rb +5 -0
  36. data/lib/mongodb_logger/server/{content_for.rb → helpers/content_for.rb} +0 -0
  37. data/lib/mongodb_logger/server/helpers/mustache_helpers.rb +66 -0
  38. data/lib/mongodb_logger/server/{partials.rb → helpers/partials.rb} +0 -0
  39. data/lib/mongodb_logger/server/{sprokets.rb → helpers/sprokets.rb} +4 -4
  40. data/lib/mongodb_logger/server/{view_helpers.rb → helpers/view_helpers.rb} +22 -38
  41. data/lib/mongodb_logger/server/model.rb +4 -0
  42. data/lib/mongodb_logger/server/model/additional_filter.rb +15 -23
  43. data/lib/mongodb_logger/server/model/analytic.rb +24 -32
  44. data/lib/mongodb_logger/server/model/base.rb +21 -0
  45. data/lib/mongodb_logger/server/model/filter.rb +12 -20
  46. data/lib/mongodb_logger/server/mustache/logs/info.rb +15 -0
  47. data/lib/mongodb_logger/server/templates/logs/info.mustache +25 -0
  48. data/lib/mongodb_logger/server/views/layout.erb +28 -26
  49. data/lib/mongodb_logger/server/views/shared/_log.erb +1 -1
  50. data/lib/mongodb_logger/server/views/shared/_tabs.erb +2 -2
  51. data/lib/mongodb_logger/server/views/shared/layout/_mustache.erb +6 -0
  52. data/lib/mongodb_logger/server/views/show_log.erb +2 -2
  53. data/lib/mongodb_logger/server_config.rb +4 -4
  54. data/lib/mongodb_logger/utils/migrate.rb +50 -0
  55. data/lib/mongodb_logger/utils/progressbar.rb +79 -0
  56. data/lib/mongodb_logger/version.rb +1 -1
  57. data/mongodb_logger.gemspec +15 -8
  58. data/{test/config/samples → spec/factories/config}/database.yml +0 -0
  59. data/{test/config/samples → spec/factories/config}/database_no_file_logging.yml +0 -0
  60. data/{test/config/samples → spec/factories/config}/database_replica_set.yml +0 -0
  61. data/{test/config/samples → spec/factories/config}/database_with_auth.yml +0 -0
  62. data/spec/factories/config/database_with_capsize.yml +9 -0
  63. data/{test/config/samples → spec/factories/config}/database_with_collection.yml +0 -0
  64. data/{test/config/samples → spec/factories/config}/database_with_url.yml +0 -0
  65. data/{test/config/samples → spec/factories/config}/mongodb_logger.yml +0 -0
  66. data/{test/config/samples → spec/factories/config}/mongoid.yml +0 -0
  67. data/{test/config/samples → spec/factories/config}/server_config.yml +0 -0
  68. data/spec/javascripts/support/jasmine.yml +1 -5
  69. data/spec/mongodb_logger_spec.rb +257 -0
  70. data/spec/rails_spec/controllers/tests_controller_spec_rails.rb +128 -0
  71. data/spec/rails_spec/spec_helper_rails.rb +13 -0
  72. data/spec/spec_helper.rb +17 -0
  73. data/{test/test_helper.rb → spec/support/mongodb_logger_helper.rb} +44 -63
  74. data/spec/support/mongodb_logger_macros.rb +22 -0
  75. data/spec/support/rails.rb +40 -0
  76. data/spec/utils/migrate_spec.rb +32 -0
  77. data/{lib/tasks → tasks}/mongodb_logger.rake +14 -6
  78. metadata +198 -78
  79. data/SUPPORTED_RAILS_VERSIONS +0 -16
  80. data/TESTING.md +0 -24
  81. data/app/assets/javascripts/vendors/jquery-1.8.3.min.js +0 -2
  82. data/features/support/terminal.rb +0 -95
  83. data/lib/mongodb_logger/server/views/shared/_log_info.erb +0 -27
  84. data/test/Gemfile_tests +0 -9
  85. data/test/active_record.rb +0 -13
  86. data/test/log/.gitkeep +0 -0
  87. data/test/rails.rb +0 -22
  88. data/test/rails/app/controllers/order_controller.rb +0 -23
  89. data/test/rails/test/functional/order_controller_test.rb +0 -116
  90. data/test/rails/test/test_helper.rb +0 -10
  91. data/test/shoulda_macros/log_macros.rb +0 -13
  92. data/test/test.sh +0 -7
  93. data/test/unit/mongodb_logger_replica_test.rb +0 -56
  94. data/test/unit/mongodb_logger_test.rb +0 -307
@@ -1,307 +0,0 @@
1
- require 'test_helper'
2
- require 'mongodb_logger'
3
- require 'mongodb_logger/logger'
4
- require 'tempfile'
5
- require 'pathname'
6
-
7
- # test the basic stuff
8
- class MongodbLogger::LoggerTest < Test::Unit::TestCase
9
- extend LogMacros
10
-
11
- EXCEPTION_MSG = "Foo"
12
-
13
- context "A MongodbLogger::Logger" do
14
- setup do
15
- # Can use different configs, but most tests use database.yml
16
- FileUtils.cp(File.join(SAMPLE_CONFIG_DIR, DEFAULT_CONFIG), CONFIG_DIR)
17
- end
18
-
19
- context "in instantiation" do
20
- setup do
21
- MongodbLogger::Logger.any_instance.stubs(:internal_initialize).returns(nil)
22
- MongodbLogger::Logger.any_instance.stubs(:disable_file_logging?).returns(false)
23
- @mongodb_logger = MongodbLogger::Logger.new
24
- end
25
-
26
- context "during configuration when using a separate " + LOGGER_CONFIG do
27
- setup do
28
- setup_for_config(LOGGER_CONFIG)
29
- end
30
-
31
- should_use_database_name_in_config
32
-
33
- teardown do
34
- teardown_for_config(LOGGER_CONFIG)
35
- end
36
- end
37
-
38
- context "during configuration when using a separate " + MONGOID_CONFIG do
39
- setup do
40
- setup_for_config(MONGOID_CONFIG)
41
- end
42
-
43
- should_use_database_name_in_config
44
-
45
- teardown do
46
- teardown_for_config(MONGOID_CONFIG)
47
- end
48
- end
49
-
50
- context "upon connecting with url settings" do
51
- setup do
52
- setup_for_config(DEFAULT_CONFIG_WITH_URL, DEFAULT_CONFIG)
53
- end
54
-
55
- should "connect with the url" do
56
- @mongodb_logger.send(:connect)
57
- assert @mongodb_logger.mongo_adapter.authenticated?
58
- assert_equal "system_log", @mongodb_logger.mongo_adapter.configuration['database']
59
- end
60
- end
61
-
62
- # this test will work without the --auth mongod arg
63
- context "upon connecting with authentication settings" do
64
- setup do
65
- setup_for_config(DEFAULT_CONFIG_WITH_AUTH, DEFAULT_CONFIG)
66
- create_mongo_user
67
- end
68
-
69
- should "authenticate with the credentials in the configuration" do
70
- @mongodb_logger.send(:connect)
71
- assert @mongodb_logger.mongo_adapter.authenticated?
72
- end
73
-
74
- teardown do
75
- # config will be deleted by outer teardown
76
- remove_mongo_user
77
- end
78
- end
79
- =begin
80
- context "after configuration" do
81
- setup do
82
- @mongodb_logger.send(:configure)
83
- @mongo_adapter = @mongodb_logger.mongo_adapter
84
- end
85
-
86
- should "set the default host, port, and capsize if not configured" do
87
- assert_equal 'localhost', @mongo_adapter.configuration['host']
88
- assert_equal 27017, @mongo_adapter.configuration['port']
89
- assert_equal MongodbLogger::Logger::DEFAULT_COLLECTION_SIZE, @mongo_adapter.configuration['capsize']
90
- end
91
-
92
- should "set the mongo collection name depending on the Rails environment" do
93
- assert_equal "#{Rails.env}_log", @mongo_adapter.collection_name
94
- end
95
-
96
- should "set the application name when specified in the config file" do
97
- assert_equal "mongo_foo", @mongo_adapter.configuration['application_name']
98
- end
99
-
100
- should "set safe insert when specified in the config file" do
101
- assert @mongo_adapter.configuration['safe_insert']
102
- end
103
-
104
- should "use the database name in the config file" do
105
- assert_equal "system_log", @mongo_adapter.configuration['database']
106
- end
107
-
108
- context "upon connecting to an empty database" do
109
- setup do
110
- @mongodb_logger.send(:connect)
111
- common_setup
112
- @collection.drop
113
- end
114
-
115
- should "expose a valid mongo connection" do
116
- assert_instance_of Mongo::DB, @mongodb_logger.mongo_connection
117
- end
118
-
119
- should "derive from Mongo::Connection for single host" do
120
- assert_equal Mongo::Connection, @mongodb_logger.mongo_connection_type
121
- end
122
-
123
- should "not authenticate" do
124
- assert !@mongodb_logger.authenticated?
125
- end
126
-
127
- should "create a capped collection in the database with the configured size" do
128
- @mongodb_logger.send(:check_for_collection)
129
- assert @con.collection_names.include?(@mongodb_logger.mongo_collection_name)
130
- # new capped collections are X MB + 5888 bytes, but don't be too strict in case that changes
131
- assert @collection.stats["storageSize"] < MongodbLogger::Logger::DEFAULT_COLLECTION_SIZE + 1.megabyte
132
- end
133
- end
134
- end
135
- =end
136
- end
137
-
138
- context "after instantiation" do
139
- setup do
140
- @mongodb_logger = MongodbLogger::Logger.new
141
- common_setup
142
- reset_collection
143
- end
144
-
145
- context "upon insertion of a log record when active record is not used" do
146
- # mock ActiveRecord has not been included
147
- setup do
148
- log("Test")
149
- end
150
-
151
- should_contain_one_log_record
152
-
153
- should "allow recreation of the capped collection to remove all records" do
154
- reset_collection
155
- assert_equal 0, @collection.count
156
- end
157
- end
158
-
159
- context "upon insertion of a colorized log record when ActiveRecord is used" do
160
- setup do
161
- @log_message = "TESTING"
162
- require_bogus_active_record
163
- log("\e[31m #{@log_message} \e[0m")
164
- end
165
-
166
- should "detect logging is colorized" do
167
- assert @mongodb_logger.send(:logging_colorized?)
168
- end
169
-
170
- should_contain_one_log_record
171
-
172
- should "strip out colorization from log messages" do
173
- assert_equal 1, @collection.find({"messages.debug" => @log_message}).count
174
- end
175
- end
176
-
177
- should "add application metadata to the log record" do
178
- options = {"application" => self.class.name}
179
- log_metadata(options)
180
- assert_equal 1, @collection.find({"application" => self.class.name}).count
181
- end
182
-
183
- should "not raise an exception when bson-unserializable data is logged in the :messages key" do
184
- log(Tempfile.new("foo"))
185
- assert_equal 1, @collection.count
186
- end
187
-
188
- should "not raise an exception when bson-unserializable data is logged in the :params key" do
189
- log_params({:foo => Tempfile.new("bar")})
190
- assert_equal 1, @collection.count
191
- end
192
-
193
- context "when an exception is raised" do
194
- should "log the exception" do
195
- assert_raise(RuntimeError, EXCEPTION_MSG) {log_exception(EXCEPTION_MSG)}
196
- assert_equal 1, @collection.find_one({"messages.error" => /^#{EXCEPTION_MSG}/})["messages"]["error"].count
197
- assert_equal 1, @collection.find_one({"is_exception" => true})["messages"]["error"].count
198
- end
199
- end
200
- end
201
-
202
- context "after configure" do
203
- setup do
204
- MongodbLogger::Base.configure do |config|
205
- config.on_log_exception do |mongo_record|
206
- # do something
207
- end
208
- end
209
- @mongodb_logger = MongodbLogger::Logger.new
210
- common_setup
211
- reset_collection
212
- end
213
-
214
- should "should not call callback function on log" do
215
- MongodbLogger::Base.expects(:on_log_exception).times(0)
216
- log("Test")
217
- end
218
-
219
- context "when an exception is raised" do
220
- should "should call callback function" do
221
- MongodbLogger::Base.expects(:on_log_exception).times(1)
222
- assert_raise(RuntimeError, EXCEPTION_MSG) {log_exception(EXCEPTION_MSG)}
223
- end
224
- end
225
- end
226
-
227
- context "logging at INFO level" do
228
- setup do
229
- @mongodb_logger = MongodbLogger::Logger.new(:level => MongodbLogger::Logger::INFO)
230
- common_setup
231
- reset_collection
232
- log("INFO")
233
- end
234
-
235
- should_contain_one_log_record
236
-
237
- should "not log DEBUG messages" do
238
- assert_equal 0, @collection.find_one({}, :fields => ["messages"])["messages"].count
239
- end
240
- end
241
- teardown do
242
- file = File.join(CONFIG_DIR, DEFAULT_CONFIG)
243
- File.delete(file) if File.exist?(file)
244
- end
245
- end
246
-
247
- context "A MongodbLogger::Logger without file logging" do
248
- setup do
249
- FileUtils.cp(File.join(SAMPLE_CONFIG_DIR, DEFAULT_CONFIG_WITH_NO_FILE_LOGGING), File.join(CONFIG_DIR, DEFAULT_CONFIG))
250
- @log_file = Pathname.new('log.out')
251
- FileUtils.touch(@log_file)
252
- end
253
-
254
- context "in instantiation" do
255
- should "not call super in the initialize method" do
256
- MongodbLogger::Logger.any_instance.expects(:open).never # Stubbing out super doesn't work, so we use this side effect instead.
257
- MongodbLogger::Logger.new
258
- end
259
-
260
- should "set log" do
261
- assert MongodbLogger::Logger.new.instance_variable_get(:@log).is_a?(Logger)
262
- end
263
- end
264
-
265
- context "after instantiation" do
266
- context "upon insertion of a log record" do
267
- setup do
268
- @mongodb_logger = MongodbLogger::Logger.new(:path => @log_file)
269
- log("Test")
270
- end
271
-
272
- should "not log the record to a file" do
273
- assert_equal '', open(@log_file.to_s).read
274
- end
275
- end
276
- end
277
-
278
- teardown do
279
- file = File.join(CONFIG_DIR, DEFAULT_CONFIG)
280
- File.delete(file) if File.exist?(file)
281
- File.delete(@log_file)
282
- end
283
- end
284
-
285
- context "A MongodbLogger::Logger with custom collection" do
286
- setup do
287
- file_path = File.join(SAMPLE_CONFIG_DIR, DEFAULT_CONFIG_WITH_COLLECTION)
288
- FileUtils.cp(file_path, File.join(CONFIG_DIR, DEFAULT_CONFIG))
289
- @mongodb_logger = MongodbLogger::Logger.new
290
- common_setup
291
- reset_collection
292
-
293
- @file_config = YAML.load(ERB.new(File.new(file_path).read).result)[Rails.env]['mongodb_logger']
294
- end
295
-
296
- should "changed collection name" do
297
- assert_equal @file_config['collection'], @collection.name
298
- assert_equal "#{@file_config['database']}.#{@file_config['collection']}", @collection.stats()['ns']
299
- end
300
-
301
- teardown do
302
- file = File.join(CONFIG_DIR, DEFAULT_CONFIG)
303
- File.delete(file) if File.exist?(file)
304
- end
305
- end
306
-
307
- end