mongodb_logger 0.2.6-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/.gitignore +20 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +19 -0
  4. data/CHANGELOG.md +30 -0
  5. data/Gemfile +10 -0
  6. data/LICENSE +22 -0
  7. data/README.md +207 -0
  8. data/Rakefile +169 -0
  9. data/SUPPORTED_RAILS_VERSIONS +17 -0
  10. data/TESTING.md +24 -0
  11. data/bin/mongodb_logger_web +24 -0
  12. data/config.ru +17 -0
  13. data/examples/server_config.yml +5 -0
  14. data/features/mongodb_logger_web.feature +14 -0
  15. data/features/rails.feature +12 -0
  16. data/features/step_definitions/mongodb_logger_web_steps.rb +45 -0
  17. data/features/step_definitions/rails_application_steps.rb +65 -0
  18. data/features/support/env.rb +15 -0
  19. data/features/support/rails.rb +98 -0
  20. data/features/support/terminal.rb +95 -0
  21. data/lib/mongodb_logger/initializer_mixin.rb +26 -0
  22. data/lib/mongodb_logger/logger.rb +239 -0
  23. data/lib/mongodb_logger/railtie.rb +12 -0
  24. data/lib/mongodb_logger/replica_set_helper.rb +19 -0
  25. data/lib/mongodb_logger/server/coffee/logs.coffee +250 -0
  26. data/lib/mongodb_logger/server/content_for.rb +58 -0
  27. data/lib/mongodb_logger/server/model/additional_filter.rb +104 -0
  28. data/lib/mongodb_logger/server/model/analytic.rb +82 -0
  29. data/lib/mongodb_logger/server/model/filter.rb +84 -0
  30. data/lib/mongodb_logger/server/partials.rb +24 -0
  31. data/lib/mongodb_logger/server/public/images/arrow-down.png +0 -0
  32. data/lib/mongodb_logger/server/public/images/arrow-up.png +0 -0
  33. data/lib/mongodb_logger/server/public/images/date.png +0 -0
  34. data/lib/mongodb_logger/server/public/images/external.png +0 -0
  35. data/lib/mongodb_logger/server/public/images/failure.png +0 -0
  36. data/lib/mongodb_logger/server/public/images/logo.png +0 -0
  37. data/lib/mongodb_logger/server/public/images/mongodb.png +0 -0
  38. data/lib/mongodb_logger/server/public/images/newlog.png +0 -0
  39. data/lib/mongodb_logger/server/public/images/play-icon.png +0 -0
  40. data/lib/mongodb_logger/server/public/images/spinner.gif +0 -0
  41. data/lib/mongodb_logger/server/public/images/spinner2.gif +0 -0
  42. data/lib/mongodb_logger/server/public/images/stop-icon.png +0 -0
  43. data/lib/mongodb_logger/server/public/images/success.png +0 -0
  44. data/lib/mongodb_logger/server/public/javascripts/logs.js +1 -0
  45. data/lib/mongodb_logger/server/public/javascripts/vendors/highlight.pack.js +1 -0
  46. data/lib/mongodb_logger/server/public/javascripts/vendors/jquery-1.7.1.min.js +4 -0
  47. data/lib/mongodb_logger/server/public/javascripts/vendors/jquery-ui-1.8.16.min.js +791 -0
  48. data/lib/mongodb_logger/server/public/javascripts/vendors/jquery.pjax.min.js +6 -0
  49. data/lib/mongodb_logger/server/public/stylesheets/all.css +12 -0
  50. data/lib/mongodb_logger/server/public/stylesheets/grids.css +18 -0
  51. data/lib/mongodb_logger/server/public/stylesheets/group-buttons.css +81 -0
  52. data/lib/mongodb_logger/server/public/stylesheets/group-forms.css +59 -0
  53. data/lib/mongodb_logger/server/public/stylesheets/group-headers.css +8 -0
  54. data/lib/mongodb_logger/server/public/stylesheets/group-tables.css +87 -0
  55. data/lib/mongodb_logger/server/public/stylesheets/highlight/zenburn.css +115 -0
  56. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_flat_75_aaaaaa_40x100.png +0 -0
  57. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_glass_100_f5f0e5_1x400.png +0 -0
  58. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_glass_25_cb842e_1x400.png +0 -0
  59. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_glass_70_ede4d4_1x400.png +0 -0
  60. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_highlight-hard_100_f4f0ec_1x100.png +0 -0
  61. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_highlight-hard_65_fee4bd_1x100.png +0 -0
  62. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_highlight-hard_75_f5f5b5_1x100.png +0 -0
  63. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-bg_inset-soft_100_f4f0ec_1x100.png +0 -0
  64. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-icons_c47a23_256x240.png +0 -0
  65. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-icons_cb672b_256x240.png +0 -0
  66. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-icons_f08000_256x240.png +0 -0
  67. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-icons_f35f07_256x240.png +0 -0
  68. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-icons_ff7519_256x240.png +0 -0
  69. data/lib/mongodb_logger/server/public/stylesheets/humanity/images/ui-icons_ffffff_256x240.png +0 -0
  70. data/lib/mongodb_logger/server/public/stylesheets/humanity/jquery-ui-1.8.16.custom.css +568 -0
  71. data/lib/mongodb_logger/server/public/stylesheets/layout.css +205 -0
  72. data/lib/mongodb_logger/server/public/stylesheets/library.css +330 -0
  73. data/lib/mongodb_logger/server/public/stylesheets/reset.css +43 -0
  74. data/lib/mongodb_logger/server/public/stylesheets/spaces.css +42 -0
  75. data/lib/mongodb_logger/server/view_helpers.rb +113 -0
  76. data/lib/mongodb_logger/server/views/analytics.erb +61 -0
  77. data/lib/mongodb_logger/server/views/error.erb +2 -0
  78. data/lib/mongodb_logger/server/views/layout.erb +47 -0
  79. data/lib/mongodb_logger/server/views/overview.erb +119 -0
  80. data/lib/mongodb_logger/server/views/shared/_collection_stats.erb +14 -0
  81. data/lib/mongodb_logger/server/views/shared/_dynamic_filter.erb +34 -0
  82. data/lib/mongodb_logger/server/views/shared/_log.erb +8 -0
  83. data/lib/mongodb_logger/server/views/shared/_log_info.erb +27 -0
  84. data/lib/mongodb_logger/server/views/shared/_message_tabs.erb +15 -0
  85. data/lib/mongodb_logger/server/views/shared/_tabs.erb +4 -0
  86. data/lib/mongodb_logger/server/views/shared/_tail_panel.erb +13 -0
  87. data/lib/mongodb_logger/server/views/shared/_top_panel.erb +7 -0
  88. data/lib/mongodb_logger/server/views/show_log.erb +105 -0
  89. data/lib/mongodb_logger/server.rb +174 -0
  90. data/lib/mongodb_logger/server_config.rb +77 -0
  91. data/lib/mongodb_logger/version.rb +3 -0
  92. data/lib/mongodb_logger.rb +31 -0
  93. data/mongodb_logger.gemspec +44 -0
  94. data/mongodb_logger.java.gemspec +42 -0
  95. data/spec/javascripts/MongodbLoggerMainSpec.js +13 -0
  96. data/spec/javascripts/helpers/SpecHelper.js +3 -0
  97. data/spec/javascripts/support/jasmine.yml +77 -0
  98. data/spec/javascripts/support/jasmine_config.rb +23 -0
  99. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  100. data/test/active_record.rb +13 -0
  101. data/test/config/samples/database.yml +9 -0
  102. data/test/config/samples/database_no_file_logging.yml +10 -0
  103. data/test/config/samples/database_replica_set.yml +12 -0
  104. data/test/config/samples/database_with_auth.yml +9 -0
  105. data/test/config/samples/database_with_collection.yml +8 -0
  106. data/test/config/samples/mongodb_logger.yml +2 -0
  107. data/test/config/samples/mongoid.yml +30 -0
  108. data/test/config/samples/server_config.yml +3 -0
  109. data/test/rails/app/controllers/order_controller.rb +23 -0
  110. data/test/rails/test/functional/order_controller_test.rb +116 -0
  111. data/test/rails/test/test_helper.rb +10 -0
  112. data/test/rails.rb +22 -0
  113. data/test/shoulda_macros/log_macros.rb +13 -0
  114. data/test/test.sh +6 -0
  115. data/test/test_helper.rb +89 -0
  116. data/test/unit/mongodb_logger_replica_test.rb +56 -0
  117. data/test/unit/mongodb_logger_test.rb +270 -0
  118. metadata +383 -0
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .project
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ test/log
19
+ tmp
20
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.3-p0@mongodb_logger_gems --create
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ before_script:
2
+ - "sh -e /etc/init.d/xvfb start"
3
+ script: "sh -c 'export DISPLAY=:99.0 && test/test.sh'"
4
+ rvm:
5
+ - 1.8.7
6
+ # - ree
7
+ - 1.9.2
8
+ - 1.9.3
9
+ - ruby-head
10
+ # - jruby-18mode
11
+ # - jruby-19mode
12
+ notifications:
13
+ email: false
14
+ branches:
15
+ only:
16
+ - master
17
+ - development
18
+ - gem
19
+ #bundler_args: --path vendor/bundle
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ ## v0.2.6
2
+
3
+ * Replica Set set in config by key 'hosts'
4
+ * Adding jruby support
5
+
6
+ ## v0.2.5
7
+
8
+ * Build graphs for analytics page
9
+ * Fix month for analytics
10
+
11
+ ## v0.2.4
12
+
13
+ * Move on logs list by using arrows on keybords
14
+
15
+ ## v0.2.3
16
+
17
+ * Fix storage log with attachments (save it for search by "original\_filename" and "content\_type")
18
+ * Fix tests for CI
19
+
20
+ ## v0.2.2
21
+
22
+ * Fix set custom collection in config and add tests on it
23
+
24
+ ## v0.2.1
25
+
26
+ * Add show on 'more info' page meta data from log
27
+
28
+ ## v0.2.0
29
+
30
+ * Public release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongodb_logger.gemspec
4
+ platforms :ruby do
5
+ gemspec(:name => "mongodb_logger")
6
+ end
7
+
8
+ platforms :jruby do
9
+ gemspec(:name => "mongodb_logger.java")
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) Alexey Vasiliev
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # MongodbLogger [![Build Status](https://secure.travis-ci.org/le0pard/mongodb_logger.png)](http://travis-ci.org/le0pard/mongodb_logger) [![Dependency Status](https://gemnasium.com/le0pard/mongodb_logger.png)](https://gemnasium.com/le0pard/mongodb_logger)
2
+
3
+ MongodbLogger is a alternative logger for Rails 3, which log all requests of you application into MongoDB database.
4
+ It:
5
+
6
+ * simple to integrate into existing Rails 3 application;
7
+ * allow to store all logs from web cluster into one scalable storage - MongoDB;
8
+ * flexible schema of MongoDB allow to store and search any information from logs;
9
+ * web panel allow filter logs, build graphs using MapReduce by information from logs;
10
+
11
+ ## Installation
12
+
13
+ 1. Add the following to your Gemfile then refresh your dependencies by executing "bundle install" (or just simple "bundle"):
14
+
15
+ gem "mongodb_logger"
16
+
17
+ 1. Add the following line to your ApplicationController:
18
+
19
+ include MongodbLogger::Base
20
+
21
+ 1. For use with Heroku you need to prevent the rails\_log\_stdout plugin from being added by Heroku:
22
+
23
+ mkdir vendor/plugins/rails_log_stdout
24
+ touch vendor/plugins/rails_log_stdout/.gitkeep
25
+
26
+ 1. Add MongodbLogger settings to database.yml for each environment in which you want to use the MongodbLogger. The MongodbLogger will also
27
+ look for a separate mongodb\_logger.yml or mongoid.yml (if you are using mongoid) before looking in database.yml.
28
+ In the mongodb\_logger.yml and mongoid.yml case, the settings should be defined without the 'mongodb\_logger' subkey.
29
+
30
+ database.yml:
31
+
32
+ development:
33
+ adapter: postgresql
34
+ database: my_app_development
35
+ username: postgres
36
+ mongodb_logger:
37
+ database: my_app # required (the only required setting)
38
+ capsize: <%= 10.megabytes %> # default: 250MB
39
+ host: localhost # default: localhost
40
+ port: 27017 # default: 27017
41
+ replica_set: true # default: false - Adds retries for ConnectionFailure during voting for replica set master
42
+ safe_insert: false # default: false - Enable/Disable safe inserts (wait for insert to propagate to all nodes)
43
+ application_name: my_app # default: Rails.application
44
+ disable_file_logging: false # default: false - disable logging into filesystem (only in MongoDB)
45
+ collection: some_name # default: Rails.env + "_log" - name of MongoDB collection
46
+
47
+ mongodb\_logger.yml:
48
+
49
+ development:
50
+ database: my_app
51
+ capsize: <%= 10.megabytes %>
52
+ host: localhost
53
+ port: 27017
54
+ replica_set: true
55
+
56
+
57
+
58
+ 1. For using with MongoDB Replica Set (more info you can read by this link [http://www.mongodb.org/display/DOCS/Replica+Sets](http://www.mongodb.org/display/DOCS/Replica+Sets)). In config set list of [host, port] in key "hosts":
59
+
60
+ development:
61
+ database: my_app
62
+ capsize: <%= 10.megabytes %>
63
+ host: localhost
64
+ port: 27017
65
+ hosts:
66
+ - - 127.0.0.1
67
+ - 27018
68
+ - - 127.0.0.1
69
+ - 27019
70
+
71
+
72
+ ## Usage
73
+
74
+ After success instalation of gem, a new MongoDB document (record) will be created for each request on your application,
75
+ by default will record the following information: Runtime, IP Address, Request Time, Controller, Method,
76
+ Action, Params, Application Name and All messages sent to the logger. The structure of the MongoDB document looks like this:
77
+
78
+ {
79
+ 'action' : action_name,
80
+ 'application_name' : application_name (rails root),
81
+ 'controller' : controller_name,
82
+ 'ip' : ip_address,
83
+ 'messages' : {
84
+ 'info' : [ ],
85
+ 'debug' : [ ],
86
+ 'error' : [ ],
87
+ 'warn' : [ ],
88
+ 'fatal' : [ ]
89
+ },
90
+ 'params' : { },
91
+ 'path' : path,
92
+ 'request_time' : date_of_request,
93
+ 'runtime' : elapsed_execution_time_in_milliseconds,
94
+ 'url' : full_url,
95
+ 'method' : request method (GET, POST, OPTIONS),
96
+ 'is_exception' : true only for exceptions (in other cases this field miss)
97
+ }
98
+
99
+ 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),
100
+ you can just call the Rails.logger.add\_metadata method on your logger like so (for example from a before\_filter):
101
+
102
+ # make sure we're using the MongodbLogger in this environment
103
+ if Rails.logger.respond_to?(:add_metadata)
104
+ Rails.logger.add_metadata(:user_id => @current_user.id)
105
+ end
106
+
107
+
108
+ ## The Front End
109
+ To setup web interface in you Rails application, first of all create autoload file in you Rails application
110
+
111
+ File: you\_rails\_app/config/initializers/mongodb\_logger.rb (example)
112
+
113
+ require 'mongodb_logger/server' # required
114
+ # this secure you web interface by basic auth, but you can skip this, if you no need this
115
+ MongodbLogger::Server.use Rack::Auth::Basic do |username, password|
116
+ [username, password] == ['admin', 'password']
117
+ end
118
+
119
+ and just mount MongodbLogger::Server in rails routes:
120
+
121
+ File: you\_rails\_app/config/routes.rb
122
+
123
+ mount MongodbLogger::Server.new, :at => "/mongodb"
124
+
125
+ Now you can see web interface by url "http://localhost:3000/mongodb"
126
+
127
+ If you've installed MongodbLogger as a gem and want running the front end without Rails application, you can do it by this command:
128
+
129
+ mongodb_logger_web config.yml
130
+
131
+ where config.yml is config, similar to config of Rails apps, but without Rails.env. Example:
132
+
133
+ database: app_logs_dev
134
+ host: localhost
135
+ port: 27017
136
+ collection: development_log # set for see development logs
137
+
138
+ parameter "collection" should be set, if your set custom for your Rails application or start this front end not for production
139
+ enviroment (by default taken "production\_log" collection, in Rails application gem generate "#{Rails.env}\_log" collection,
140
+ if it is not defined in config).
141
+
142
+ It's a thin layer around rackup so it's configurable as well:
143
+
144
+ mongodb_logger_web config.yml -p 8282
145
+
146
+ ### Passenger, Unicorn, Thin, etc.
147
+
148
+ Using Passenger, Unicorn, Thin, etc? MongodbLogger ships with a `config.ru` you can use. See guide:
149
+
150
+ * Passenger Apache: <http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_rack_based_ruby_application>
151
+ * Passenger Nginx: <http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_a_rack_app>
152
+ * Unicorn: <http://unicorn.bogomips.org>
153
+ * Thin: <http://code.macournoyer.com/thin/usage>
154
+
155
+ Don't forget setup MONGODBLOGGERCONFIG env variable, which provide information about MongodbLogger config. Example starting with unicorn:
156
+
157
+ MONGODBLOGGERCONFIG=examples/server_config.yml unicorn
158
+
159
+ ## Demo Application with MongodbLogger
160
+
161
+ Demo: [http://demo-mongodb-logger.catware.org/](http://demo-mongodb-logger.catware.org/)
162
+
163
+ Demo Sources: [https://github.com/le0pard/mongodb_logger_example_heroku](https://github.com/le0pard/mongodb_logger_example_heroku)
164
+
165
+
166
+ ## Querying via the Rails console
167
+
168
+ And now, for a couple quick examples on getting ahold of this log data...
169
+ First, here's how to get a handle on the MongoDB from within a Rails console:
170
+
171
+ >> db = Rails.logger.mongo_connection
172
+ => #<Mongo::DB:0x007fdc7c65adc8 @name="monkey_logs_dev" ... >
173
+
174
+ >> collection = db[Rails.logger.mongo_collection_name]
175
+ => #<Mongo::Collection:0x007fdc7a4d12b0 @name="development_log" .. >
176
+
177
+ Once you've got the collection, you can find all requests for a specific user (with id):
178
+
179
+ >> cursor = collection.find(:user_id => '12355')
180
+ => #<Mongo::Cursor:0x1031a3e30 ... >
181
+ >> cursor.count
182
+ => 5
183
+
184
+ Find all requests that took more that one second to complete:
185
+
186
+ >> collection.find({:runtime => {'$gt' => 1000}}).count
187
+ => 3
188
+
189
+ Find all order#show requests with a particular order id (id=order\_id):
190
+
191
+ >> collection.find({"controller" => "order", "action"=> "show", "params.id" => order_id})
192
+
193
+ Find all requests with an exception that contains "RoutingError" in the message or stack trace:
194
+
195
+ >> collection.find({"messages.error" => /RoutingError/})
196
+
197
+ Find all requests with errors:
198
+
199
+ >> collection.find({"is_exception" => true})
200
+
201
+ Find all requests with a request\_date greater than '11/18/2010 22:59:52 GMT'
202
+
203
+ >> collection.find({:request_time => {'$gt' => Time.utc(2010, 11, 18, 22, 59, 52)}})
204
+
205
+
206
+
207
+ Copyright (c) 2009-2012 Phil Burrows, CustomInk (based on https://github.com/customink/central_logger) and Leopard released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env rake
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ begin
5
+ require 'cucumber/rake/task'
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.java')
14
+ Bundler::GemHelper.install_tasks(:name => 'mongodb_logger')
15
+
16
+
17
+ #########################################
18
+ ### Help tasks
19
+ #########################################
20
+
21
+ require 'coffee-script'
22
+ require 'uglifier'
23
+ namespace :js do
24
+ desc "compile coffee-scripts from ./lib/mongodb_logger/server/coffee to ./lib/mongodb_logger/server/public/javascripts"
25
+ task :compile do
26
+ source = "#{File.dirname(__FILE__)}/lib/mongodb_logger/server/coffee/"
27
+ javascripts = "#{File.dirname(__FILE__)}/lib/mongodb_logger/server/public/javascripts/"
28
+
29
+ Dir.foreach(source) do |cf|
30
+ unless cf == '.' || cf == '..'
31
+ js_compiled = CoffeeScript.compile File.read("#{source}#{cf}")
32
+ js = Uglifier.compile js_compiled
33
+ open "#{javascripts}#{cf.gsub('.coffee', '.js')}", 'w' do |f|
34
+ f.puts js
35
+ end
36
+ end
37
+ end
38
+
39
+ puts "All done."
40
+ end
41
+ end
42
+
43
+ #########################################
44
+ ### TESTS
45
+ #########################################
46
+
47
+ desc 'Default: run unit tests.'
48
+ task :default => [:test]
49
+ #task :default => [:test, "cucumber:rails:all"]
50
+
51
+ desc "Clean out the tmp directory"
52
+ task :clean do
53
+ exec "rm -rf tmp"
54
+ end
55
+
56
+ desc 'Test unit.'
57
+ Rake::TestTask.new(:test) do |test|
58
+ test.libs << 'lib' << 'test'
59
+ test.test_files = ['test/unit/mongodb_logger_test.rb']
60
+ test.verbose = true
61
+ end
62
+
63
+ namespace :test do
64
+
65
+ desc "Run replica set tests (not for CI)"
66
+ Rake::TestTask.new(:replica_set) do |test|
67
+ test.libs << 'lib' << 'test'
68
+ test.pattern = 'test/unit/mongodb_logger_replica_test.rb'
69
+ test.verbose = true
70
+ end
71
+
72
+ end
73
+
74
+
75
+ GEM_ROOT = File.dirname(__FILE__).freeze
76
+ LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
77
+
78
+ if ENV['CI']
79
+ # for ci testing only major rails versions
80
+ RAILS_VERSIONS = ['3.0.11', '3.1.3', '3.2.0']
81
+ else
82
+ RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
83
+ end
84
+
85
+
86
+ LOCAL_GEMS = [['sqlite3', nil], ['shoulda', nil], ["rspec", nil], ["mocha", nil], ["cucumber", nil], ["bundler", "1.0.21"]] +
87
+ RAILS_VERSIONS.collect { |version| ['rails', version] }
88
+
89
+ desc "Vendor test gems: Run this once to prepare your test environment"
90
+ task :vendor_test_gems do
91
+ old_gem_path = ENV['GEM_PATH']
92
+ old_gem_home = ENV['GEM_HOME']
93
+ ENV['GEM_PATH'] = LOCAL_GEM_ROOT
94
+ ENV['GEM_HOME'] = LOCAL_GEM_ROOT
95
+ LOCAL_GEMS.each do |gem_name, version|
96
+ gem_file_pattern = [gem_name, version || '*'].compact.join('-')
97
+ version_option = version ? "-v #{version}" : ''
98
+ pattern = File.join(LOCAL_GEM_ROOT, 'gems', "#{gem_file_pattern}")
99
+ existing = Dir.glob(pattern).first
100
+ unless existing
101
+ command = "gem install -i #{LOCAL_GEM_ROOT} --no-ri --no-rdoc --backtrace #{version_option} #{gem_name}"
102
+ puts "Vendoring #{gem_file_pattern}..."
103
+ unless system("#{command} 2>&1")
104
+ puts "Command failed: #{command}"
105
+ exit(1)
106
+ end
107
+ end
108
+ end
109
+ ENV['GEM_PATH'] = old_gem_path
110
+ ENV['GEM_HOME'] = old_gem_home
111
+ end
112
+
113
+ Cucumber::Rake::Task.new(:cucumber) do |t|
114
+ t.fork = true
115
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
116
+ end
117
+
118
+ task :cucumber => [:vendor_test_gems]
119
+
120
+ def run_rails_cucumbr_task(version, additional_cucumber_args)
121
+ puts "Testing Rails #{version}"
122
+ if version.empty?
123
+ raise "No Rails version specified - make sure ENV['RAILS_VERSION'] is set, e.g. with `rake cucumber:rails:all`"
124
+ end
125
+ ENV['RAILS_VERSION'] = version
126
+ system("cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/rails.feature")
127
+ end
128
+
129
+ def define_rails_cucumber_tasks(additional_cucumber_args = '')
130
+ namespace :rails do
131
+ RAILS_VERSIONS.each do |version|
132
+ desc "Test integration of the gem with Rails #{version}"
133
+ task version => [:vendor_test_gems] do
134
+ exit 1 unless run_rails_cucumbr_task(version, additional_cucumber_args)
135
+ end
136
+ end
137
+
138
+ desc "Test integration of the gem with all Rails versions"
139
+ task :all do
140
+ results = RAILS_VERSIONS.map do |version|
141
+ run_rails_cucumbr_task(version, additional_cucumber_args)
142
+ end
143
+
144
+ exit 1 unless results.all?
145
+ end
146
+ end
147
+ end
148
+
149
+ def define_web_cucumber_tasks(additional_cucumber_args = '')
150
+ desc "Test web of the gem"
151
+ task :web do
152
+ puts "Testing Web"
153
+ system("cucumber --format #{ENV['CUCUMBER_FORMAT'] || 'progress'} #{additional_cucumber_args} features/mongodb_logger_web.feature")
154
+ end
155
+ end
156
+
157
+ namespace :cucumber do
158
+ define_rails_cucumber_tasks
159
+ define_web_cucumber_tasks
160
+ end
161
+
162
+ begin
163
+ require 'jasmine'
164
+ load 'jasmine/tasks/jasmine.rake'
165
+ rescue LoadError
166
+ task :jasmine do
167
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
168
+ end
169
+ end
@@ -0,0 +1,17 @@
1
+ 3.0.0
2
+ 3.0.1
3
+ 3.0.2
4
+ 3.0.3
5
+ 3.0.4
6
+ 3.0.5
7
+ 3.0.6
8
+ 3.0.7
9
+ 3.0.8
10
+ 3.0.9
11
+ 3.0.10
12
+ 3.0.11
13
+ 3.1.0
14
+ 3.1.1
15
+ 3.1.2
16
+ 3.1.3
17
+ 3.2.0
data/TESTING.md ADDED
@@ -0,0 +1,24 @@
1
+ Running the suite
2
+ =================
3
+
4
+ Since the logger must run on many versions of Rails, running its test suite is slightly different than you may be used to.
5
+
6
+ First execute the following command:
7
+
8
+ rake vendor_test_gems
9
+ # NOT: bundle exec rake vendor_test_gems
10
+
11
+ This command will download the various versions of Rails that the notifier must be tested against.
12
+
13
+ Then, to start the suite, run
14
+
15
+ rake cucumber:rails:all
16
+
17
+ Note: do NOT use 'bundle exec rake cucumber:rails:all'.
18
+
19
+ For help created file test/test.sh, which run all this testing steps + unit tests. Run this file from root of gem:
20
+
21
+ ./test/test.sh
22
+
23
+ Versions of testing Rails you can see in file "SUPPORTED_RAILS_VERSIONS". If some tests is faild, you can see
24
+ more information about fallen tests in file "tmp/terminal.log".
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ begin
5
+ require 'vegas'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'vegas'
9
+ end
10
+ require 'mongodb_logger/server'
11
+
12
+
13
+ Vegas::Runner.new(MongodbLogger::Server, 'mongodb_logger_web', {
14
+ :before_run => lambda {|v|
15
+ config_file = (ENV['MONGODBLOGGERCONFIG'] || v.args.first)
16
+ if config_file
17
+ MongodbLogger::ServerConfig.set_config(config_file)
18
+ else
19
+ raise ArgumentError, "please provide config file"
20
+ end
21
+ }
22
+ }) do |runner, opts, app|
23
+ #
24
+ end
data/config.ru ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require 'logger'
3
+
4
+ $LOAD_PATH.unshift ::File.expand_path(::File.dirname(__FILE__) + '/lib')
5
+ require 'mongodb_logger/server'
6
+
7
+ # Set the MONGODBLOGGERCONFIG env variable
8
+ # config file you want loaded on boot.
9
+ if ENV['MONGODBLOGGERCONFIG'] && ::File.exists?(::File.expand_path(ENV['MONGODBLOGGERCONFIG']))
10
+ MongodbLogger::ServerConfig.set_config(::File.expand_path(ENV['MONGODBLOGGERCONFIG']))
11
+ use Rack::ShowExceptions
12
+ run MongodbLogger::Server.new
13
+ else
14
+ raise "Please provide config file"
15
+ exit 1
16
+ end
17
+
@@ -0,0 +1,5 @@
1
+ database: monkey_logs_dev
2
+ host: localhost
3
+ port: 27017
4
+ collection: development_log
5
+ #collection: prod_imported
@@ -0,0 +1,14 @@
1
+ Feature: Install MongodbLogger Web and test it
2
+
3
+ Scenario: Main page
4
+ Given homepage
5
+ Then I should see text that no logs in system
6
+
7
+ Scenario: Tail logs buttons
8
+ Given homepage
9
+ And I should see start tail button
10
+ When I click on start tail button
11
+ Then I should see stop tails button
12
+ And box with time of last log tail
13
+ When I click on stop tail button
14
+ Then I should see start tail button
@@ -0,0 +1,12 @@
1
+ Feature: Install the Gem in a Rails application and test it
2
+
3
+ Background:
4
+ Given I have built and installed the "mongodb_logger" gem
5
+
6
+ Scenario: Use the gem without vendoring the gem in a Rails application
7
+ When I generate a new Rails application
8
+ And I configure my application to require the "mongodb_logger" gem
9
+ And I setup mongodb_logger tests
10
+ And I setup all gems for rails
11
+ And I prepare rails environment for testing
12
+ Then the tests should have run successfully
@@ -0,0 +1,45 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'mongodb_logger/server'
3
+ require 'capybara/cucumber'
4
+
5
+ include Capybara::DSL
6
+
7
+ Before do
8
+ MongodbLogger::ServerConfig.set_config_for_testing(File.join(PROJECT_ROOT, 'test/config/samples/server_config.yml'))
9
+ Capybara.app = MongodbLogger::Server
10
+ end
11
+
12
+ After do
13
+ MongodbLogger::ServerConfig.collection.drop
14
+ end
15
+
16
+ Given /^homepage$/ do
17
+ visit "/"
18
+ end
19
+
20
+ Then /^I should see text that no logs in system$/ do
21
+ page.has_selector?('div', :text => 'No logs found, try to filter out the other parameters', :visible => true)
22
+ end
23
+
24
+ Given /^I should see start tail button$/ do
25
+ page.has_link?('tail_logs_link', :visible => true)
26
+ page.has_link?('tail_logs_stop_link', :visible => false)
27
+ end
28
+
29
+ When /^I click on start tail button$/ do
30
+ click_link('tail_logs_link')
31
+ end
32
+
33
+ Then /^I should see stop tails button$/ do
34
+ page.has_link?('tail_logs_link', :visible => false)
35
+ page.has_link?('tail_logs_stop_link', :visible => true)
36
+ end
37
+
38
+ Then /^box with time of last log tail$/ do
39
+ page.has_selector?('span', :id => 'tail_logs_time', :visible => true)
40
+ end
41
+
42
+ When /^I click on stop tail button$/ do
43
+ click_link('tail_logs_stop_link')
44
+ end
45
+