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.
Files changed (61) hide show
  1. data/.rvmrc +1 -1
  2. data/.travis.yml +13 -7
  3. data/Gemfile +1 -7
  4. data/README.md +128 -117
  5. data/Rakefile +11 -40
  6. data/SUPPORTED_RAILS_VERSIONS +3 -1
  7. data/app/assets/javascripts/analytics.js.coffee +66 -0
  8. data/app/assets/javascripts/logs.js.coffee +107 -164
  9. data/app/assets/javascripts/mongodb_logger.js +11 -2
  10. data/app/assets/javascripts/vendors/jquery-1.8.3.min.js +2 -0
  11. data/app/assets/javascripts/vendors/jquery-ui-1.9.2.min.js +6 -0
  12. data/app/assets/javascripts/vendors/jquery.pjax.min.js +13 -6
  13. data/app/assets/javascripts/vendors/rickshaw/d3.layout.min.js +1 -0
  14. data/app/assets/javascripts/vendors/rickshaw/d3.min.js +2 -0
  15. data/app/assets/javascripts/vendors/rickshaw/rickshaw.js +2637 -0
  16. data/app/assets/stylesheets/humanity/{jquery-ui-1.8.16.custom.css → jquery-ui-1.9.2.custom.css} +0 -0
  17. data/app/assets/stylesheets/layout.css +1 -1
  18. data/app/assets/stylesheets/library.css.erb +2 -2
  19. data/app/assets/stylesheets/mongodb_logger.css +2 -1
  20. data/app/assets/stylesheets/rickshaw/rickshaw.css +307 -0
  21. data/bin/mongodb_logger_web +1 -2
  22. data/config.ru +8 -1
  23. data/examples/server_config.yml +1 -2
  24. data/features/mongodb_logger_web.feature +1 -1
  25. data/features/step_definitions/mongodb_logger_web_steps.rb +18 -12
  26. data/lib/mongodb_logger.rb +6 -2
  27. data/lib/mongodb_logger/adapters.rb +3 -0
  28. data/lib/mongodb_logger/adapters/base.rb +45 -0
  29. data/lib/mongodb_logger/adapters/mongo.rb +91 -0
  30. data/lib/mongodb_logger/adapters/moped.rb +95 -0
  31. data/lib/mongodb_logger/logger.rb +39 -71
  32. data/lib/mongodb_logger/replica_set_helper.rb +11 -2
  33. data/lib/mongodb_logger/server.rb +15 -36
  34. data/lib/mongodb_logger/server/model/analytic.rb +54 -37
  35. data/lib/mongodb_logger/server/view_helpers.rb +5 -1
  36. data/lib/mongodb_logger/server/views/analytics.erb +8 -7
  37. data/lib/mongodb_logger/server/views/layout.erb +4 -11
  38. data/lib/mongodb_logger/server/views/overview.erb +6 -6
  39. data/lib/mongodb_logger/server/views/shared/_collection_stats.erb +4 -4
  40. data/lib/mongodb_logger/server/views/shared/_dynamic_filter.erb +1 -1
  41. data/lib/mongodb_logger/server/views/shared/_log_info.erb +1 -1
  42. data/lib/mongodb_logger/server/views/shared/_tabs.erb +2 -2
  43. data/lib/mongodb_logger/server/views/shared/_tail_panel.erb +4 -4
  44. data/lib/mongodb_logger/server/views/shared/_top_panel.erb +1 -1
  45. data/lib/mongodb_logger/server/views/show_log.erb +11 -1
  46. data/lib/mongodb_logger/server_config.rb +17 -66
  47. data/lib/mongodb_logger/version.rb +1 -1
  48. data/mongodb_logger.gemspec +19 -20
  49. data/spec/javascripts/MongodbLoggerMainSpec.js +2 -2
  50. data/spec/javascripts/support/jasmine.yml +5 -5
  51. data/test/Gemfile_tests +2 -1
  52. data/test/config/samples/database.yml +3 -1
  53. data/test/config/samples/database_no_file_logging.yml +3 -1
  54. data/test/shoulda_macros/log_macros.rb +1 -1
  55. data/test/test.sh +5 -5
  56. data/test/test_helper.rb +26 -18
  57. data/test/unit/mongodb_logger_test.rb +21 -20
  58. metadata +70 -88
  59. data/app/assets/javascripts/vendors/jquery-1.7.1.min.js +0 -4
  60. data/app/assets/javascripts/vendors/jquery-ui-1.8.16.min.js +0 -791
  61. data/mongodb_logger.java.gemspec +0 -43
@@ -3,5 +3,5 @@
3
3
  <div class="unit-right">
4
4
  <% yield_content :right_top_panel %>
5
5
  </div> <!-- unit-right -->
6
- <div id="ajax_loader"><img src="<%= asset_path 'spinner.gif' %>" alt="loading..."></div>
6
+ <div id="ajaxLoader"><img src="<%= asset_path 'spinner.gif' %>" alt="loading..."></div>
7
7
  </div> <!-- topline -->
@@ -2,7 +2,7 @@
2
2
 
3
3
  <div class="unit-right">
4
4
  <div class="pam">
5
- <a href="<%=h url_path("overview") %>" data-pjax='#main_pjax' class="button small grey">Back</a>
5
+ <a href="<%=h url_path("overview") %>" data-pjax='#mainPjax' class="button small grey">Back</a>
6
6
  </div> <!-- pam -->
7
7
  </div> <!-- unit-right -->
8
8
  <h1 class="pam">Log #<%=h @log['_id'] %></h1>
@@ -102,4 +102,14 @@
102
102
  </div> <!-- unit -->
103
103
  </li>
104
104
  <% end %>
105
+ <% unless @log['session'].blank? %>
106
+ <li class="outer pvs phm">
107
+ <div class="unit size1of5">
108
+ <span class="pale">Session:</span>
109
+ </div> <!-- unit -->
110
+ <div class="unit size4of5">
111
+ <pre><code><%= pretty_hash(@log['session']) %></code></pre>
112
+ </div> <!-- unit -->
113
+ </li>
114
+ <% end %>
105
115
  </ul>
@@ -1,76 +1,27 @@
1
- require 'mongo'
2
- require 'erb'
3
- require 'active_support'
4
- require 'active_support/core_ext'
1
+ require 'mongodb_logger/logger'
5
2
 
6
- # TODO: Dry this class with logger class
7
3
  module MongodbLogger
8
4
  class ServerConfig
9
5
 
10
- DEFAULT_COLLECTION_SIZE = 250.megabytes
11
-
6
+ class ServerLogger < MongodbLogger::Logger
7
+ private
8
+ def resolve_config
9
+ config_file = ENV['MONGODBLOGGERCONFIG']
10
+ config = YAML.load(ERB.new(File.read(config_file)).result)
11
+ config = config['mongodb_logger'] if config && config.has_key?('mongodb_logger')
12
+ config
13
+ end
14
+ end
15
+
12
16
  class << self
13
-
14
17
  def set_config(config_path)
15
- if File.file?(config_path)
16
- config_file = File.new(config_path)
17
- config = YAML.load(ERB.new(config_file.read).result)
18
- else
19
- raise "Config file not found"
20
- end
21
-
22
- @db_configuration = {
23
- 'host' => 'localhost',
24
- 'port' => 27017}.merge(config)
25
- @db_configuration["collection"] ||= "production_log"
26
- @db = Mongo::Connection.new(@db_configuration['host'],
27
- @db_configuration['port'],
28
- :connect => true).db(@db_configuration['database'])
29
-
30
- if @db_configuration['username'] && @db_configuration['password']
31
- @authenticated = @db.authenticate(@db_configuration['username'],
32
- @db_configuration['password'])
33
- end
34
-
35
- set_collection
36
- end
37
-
38
- def set_config_for_testing(config_path)
39
- set_config(config_path)
40
- create_collection unless @db.collection_names.include?(@db_configuration["collection"])
41
- set_collection
42
- end
43
-
44
- def create_collection
45
- capsize = DEFAULT_COLLECTION_SIZE
46
- capsize = @db_configuration['capsize'].to_i if @db_configuration['capsize']
47
- @db.create_collection(@db_configuration["collection"],
48
- {:capped => true, :size => capsize})
49
- end
50
-
51
-
52
- def set_collection
53
- @collection = @db[@db_configuration["collection"]]
54
- end
55
-
56
- def get_config
57
- @db_configuration
58
- end
59
-
60
- def authenticated?
61
- @authenticated
62
- end
63
-
64
- def collection_name
65
- @db_configuration["collection"]
66
- end
67
-
68
- def db
69
- @db
18
+ ENV['MONGODBLOGGERCONFIG'] = config_path
19
+ @logger = ServerLogger.new(:path => "server.log")
20
+ @logger.mongo_adapter
70
21
  end
71
-
72
- def collection
73
- @collection
22
+
23
+ def mongo_adapter
24
+ @logger.mongo_adapter if @logger
74
25
  end
75
26
  end
76
27
  end
@@ -1,3 +1,3 @@
1
1
  module MongodbLogger
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -11,27 +11,26 @@ Gem::Specification.new do |gem|
11
11
  gem.extra_rdoc_files = [ "LICENSE", "README.md" ]
12
12
  gem.rdoc_options = ["--charset=UTF-8"]
13
13
 
14
- gem.add_development_dependency "jasmine", ">= 1.0.0"
15
- gem.add_development_dependency "rspec", ">= 2.8.0"
16
- gem.add_development_dependency "shoulda", ">= 2.0.0"
17
- gem.add_development_dependency "mocha", ">= 0.10.0"
18
- gem.add_development_dependency "cucumber", ">= 1.1.2"
19
- gem.add_development_dependency "capybara", ">= 1.1.2"
20
- gem.add_development_dependency "uglifier", ">= 1.2.0"
21
- gem.add_development_dependency "therubyracer", ">= 0.9.9"
14
+ gem.add_development_dependency "rspec"
15
+ gem.add_development_dependency "shoulda"
16
+ gem.add_development_dependency "mocha"
17
+ gem.add_development_dependency "cucumber"
18
+ gem.add_development_dependency "capybara"
19
+ gem.add_development_dependency "coffee-script"
20
+ gem.add_development_dependency "uglifier"
21
+ gem.add_development_dependency "jasmine"
22
+ # adapters
23
+ gem.add_development_dependency "mongo"
24
+ gem.add_development_dependency "moped"
22
25
 
23
- gem.add_runtime_dependency "rake", ">= 0.9.0"
24
- gem.add_runtime_dependency "mongo", ">= 1.6.1"
25
- gem.add_runtime_dependency "bson_ext", ">= 1.6.1"
26
- gem.add_runtime_dependency "i18n", ">= 0.4.1"
27
- gem.add_runtime_dependency "json", ">= 1.6.1"
28
- gem.add_runtime_dependency "activesupport", ">= 3.0.0"
29
- gem.add_runtime_dependency "actionpack", ">= 3.0.0"
30
- gem.add_runtime_dependency "sprockets", ">= 2.0.0"
31
- gem.add_runtime_dependency "coffee-script", ">= 2.2.0"
32
- gem.add_runtime_dependency "sinatra", ">= 1.2.0"
33
- gem.add_runtime_dependency "erubis", ">= 2.6.6"
34
- gem.add_runtime_dependency "vegas", ">= 0.1.2"
26
+ gem.add_dependency "rake", ">= 0.9.0"
27
+ gem.add_dependency "json", "~> 1.7.0"
28
+ gem.add_dependency "activesupport", ">= 3.1.0"
29
+ gem.add_dependency "actionpack", ">= 3.1.0"
30
+ gem.add_dependency "sprockets", ">= 2.0.0"
31
+ gem.add_dependency "sinatra", "~> 1.3.0"
32
+ gem.add_dependency "erubis", "~> 2.7.0"
33
+ gem.add_dependency "vegas", "~> 0.1.0"
35
34
 
36
35
  gem.rubyforge_project = "mongodb_logger"
37
36
 
@@ -4,9 +4,9 @@ describe("MongodbLoggerMain", function() {
4
4
  MongodbLoggerMain.init();
5
5
  });
6
6
 
7
- describe("log_info_padding", function() {
7
+ describe("logInfoPadding", function() {
8
8
  it("should be 15", function() {
9
- expect(MongodbLoggerMain.log_info_padding).toEqual(15);
9
+ expect(MongodbLoggerMain.logInfoPadding).toEqual(15);
10
10
  });
11
11
  });
12
12
 
@@ -11,11 +11,11 @@
11
11
  # - dist/**/*.js
12
12
  #
13
13
  src_files:
14
- - lib/mongodb_logger/server/public/javascripts/vendors/jquery-1.7.1.min.js
15
- - lib/mongodb_logger/server/public/javascripts/vendors/jquery-ui-1.8.16.min.js
16
- - lib/mongodb_logger/server/public/javascripts/vendors/jquery.pjax.min.js
17
- - lib/mongodb_logger/server/public/javascripts/vendors/highlight.pack.js
18
- - lib/mongodb_logger/server/public/javascripts/logs.js
14
+ - app/assets/javascripts/vendors/jquery-1.8.3.min.js
15
+ - app/assets/javascripts/vendors/jquery-ui-1.9.2.min.js
16
+ - app/assets/javascripts/vendors/jquery.pjax.min.js
17
+ - app/assets/javascripts/vendors/highlight.pack.js
18
+ - app/assets/javascripts/logs.js
19
19
 
20
20
  # stylesheets
21
21
  #
data/test/Gemfile_tests CHANGED
@@ -5,4 +5,5 @@ gem "rspec", ">= 2.8.0"
5
5
  gem "shoulda", ">= 2.0.0"
6
6
  gem "mocha", ">= 0.10.0"
7
7
  gem "cucumber", "~> 1.1.2"
8
- gem "capybara", "~> 1.1.2"
8
+ gem "capybara", "~> 1.1.2"
9
+ gem "i18n"
@@ -6,4 +6,6 @@ test:
6
6
  mongodb_logger:
7
7
  database: system_log
8
8
  application_name: mongo_foo
9
- safe_insert: true
9
+ write_options:
10
+ w: 1
11
+ wtimeout: 200
@@ -6,5 +6,7 @@ test:
6
6
  mongodb_logger:
7
7
  database: system_log
8
8
  application_name: mongo_foo
9
- safe_insert: true
9
+ write_options:
10
+ w: 1
11
+ wtimeout: 200
10
12
  disable_file_logging: true
@@ -1,7 +1,7 @@
1
1
  module LogMacros
2
2
  def should_contain_one_log_record
3
3
  should "contain a log record" do
4
- assert_equal 1, @con[@mongodb_logger.mongo_collection_name].count
4
+ assert_equal 1, @collection.count
5
5
  end
6
6
  end
7
7
 
data/test/test.sh CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
- BUNDLE_GEMFILE=test/Gemfile_tests bundle
3
- BUNDLE_GEMFILE=test/Gemfile_tests rake vendor_test_gems && \
4
- rake test && \
5
- rake cucumber:web && \
2
+ bundle exec rake test && \
3
+ bundle exec rake cucumber:web
4
+ #bundle exec rake vendor_test_gems && \
5
+ # && \
6
6
  #rake jasmine:ci && \
7
- rake cucumber:rails:all
7
+ #rake cucumber:rails:all
data/test/test_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
- require 'test/unit'
1
+ require 'rubygems'
2
+ require 'bundler'
2
3
 
3
- begin
4
- require 'shoulda'
5
- rescue LoadError
6
- require 'rubygems'
7
- require 'shoulda'
8
- end
4
+ Bundler.require
5
+
6
+ require 'test/unit'
7
+ require "mocha"
8
+ require 'mocha/api'
9
+ require 'shoulda'
9
10
 
10
- require 'mocha'
11
11
  # mock rails class
12
12
  require 'pathname'
13
13
  require 'rails'
@@ -46,18 +46,18 @@ class Test::Unit::TestCase
46
46
  end
47
47
  end
48
48
 
49
- def setup_for_config(source, dest=source)
49
+ def setup_for_config(source, dest = source)
50
50
  File.delete(File.join(CONFIG_DIR, DEFAULT_CONFIG))
51
51
  cp_config(source, dest)
52
52
  @mongodb_logger.send(:configure)
53
53
  end
54
54
 
55
- def cp_config(source, dest=source)
55
+ def cp_config(source, dest = source)
56
56
  FileUtils.cp(File.join(SAMPLE_CONFIG_DIR, source), File.join(CONFIG_DIR, dest))
57
57
  end
58
58
 
59
59
  def teardown_for_config(file)
60
- File.delete(File.join(CONFIG_DIR, file))
60
+ File.delete(File.join(CONFIG_DIR, file)) if File.exists?(File.join(CONFIG_DIR, file))
61
61
  end
62
62
 
63
63
  def log_metadata(options)
@@ -71,20 +71,28 @@ class Test::Unit::TestCase
71
71
  end
72
72
 
73
73
  def common_setup
74
- @con = @mongodb_logger.mongo_connection
75
- @collection = @con[@mongodb_logger.mongo_collection_name]
74
+ @mongo_adapter = @mongodb_logger.mongo_adapter
75
+ @con = @mongo_adapter.connection
76
+ @collection = @mongo_adapter.collection
77
+ end
78
+
79
+ def reset_collection
80
+ if @mongo_adapter && @collection
81
+ @collection.drop
82
+ @mongo_adapter.create_collection
83
+ end
76
84
  end
77
85
 
78
- def create_user
86
+ def create_mongo_user
79
87
  db_conf = @mongodb_logger.db_configuration
80
88
  @user = db_conf['username']
81
- mongo_connection = Mongo::Connection.new(db_conf['host'],
89
+ @mongo_connection = ::Mongo::Connection.new(db_conf['host'],
82
90
  db_conf['port']).db(db_conf['database'])
83
- mongo_connection.add_user(@user, db_conf['password'])
91
+ @mongo_connection.add_user(@user, db_conf['password'])
84
92
  end
85
93
 
86
- def remove_user
87
- @mongodb_logger.mongo_connection.remove_user(@user)
94
+ def remove_mongo_user
95
+ @mongo_connection.remove_user(@user)
88
96
  end
89
97
 
90
98
  end
@@ -54,9 +54,8 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
54
54
 
55
55
  should "connect with the url" do
56
56
  @mongodb_logger.send(:connect)
57
- assert @mongodb_logger.authenticated?
58
- assert_equal "system_log", @mongodb_logger.mongo_connection.name
59
- assert_equal ["localhost", 27017], @mongodb_logger.mongo_connection.connection.primary
57
+ assert @mongodb_logger.mongo_adapter.authenticated?
58
+ assert_equal "system_log", @mongodb_logger.mongo_adapter.configuration['database']
60
59
  end
61
60
  end
62
61
 
@@ -64,45 +63,46 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
64
63
  context "upon connecting with authentication settings" do
65
64
  setup do
66
65
  setup_for_config(DEFAULT_CONFIG_WITH_AUTH, DEFAULT_CONFIG)
67
- create_user
66
+ create_mongo_user
68
67
  end
69
68
 
70
69
  should "authenticate with the credentials in the configuration" do
71
70
  @mongodb_logger.send(:connect)
72
- assert @mongodb_logger.authenticated?
71
+ assert @mongodb_logger.mongo_adapter.authenticated?
73
72
  end
74
73
 
75
74
  teardown do
76
75
  # config will be deleted by outer teardown
77
- remove_user
76
+ remove_mongo_user
78
77
  end
79
78
  end
80
-
79
+ =begin
81
80
  context "after configuration" do
82
81
  setup do
83
82
  @mongodb_logger.send(:configure)
83
+ @mongo_adapter = @mongodb_logger.mongo_adapter
84
84
  end
85
85
 
86
86
  should "set the default host, port, and capsize if not configured" do
87
- assert_equal 'localhost', @mongodb_logger.db_configuration['host']
88
- assert_equal 27017, @mongodb_logger.db_configuration['port']
89
- assert_equal MongodbLogger::Logger::DEFAULT_COLLECTION_SIZE, @mongodb_logger.db_configuration['capsize']
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
90
  end
91
91
 
92
92
  should "set the mongo collection name depending on the Rails environment" do
93
- assert_equal "#{Rails.env}_log", @mongodb_logger.mongo_collection_name
93
+ assert_equal "#{Rails.env}_log", @mongo_adapter.collection_name
94
94
  end
95
95
 
96
96
  should "set the application name when specified in the config file" do
97
- assert_equal "mongo_foo", @mongodb_logger.instance_variable_get(:@application_name)
97
+ assert_equal "mongo_foo", @mongo_adapter.configuration['application_name']
98
98
  end
99
99
 
100
100
  should "set safe insert when specified in the config file" do
101
- assert @mongodb_logger.instance_variable_get(:@safe_insert)
101
+ assert @mongo_adapter.configuration['safe_insert']
102
102
  end
103
103
 
104
104
  should "use the database name in the config file" do
105
- assert_equal "system_log", @mongodb_logger.db_configuration['database']
105
+ assert_equal "system_log", @mongo_adapter.configuration['database']
106
106
  end
107
107
 
108
108
  context "upon connecting to an empty database" do
@@ -132,13 +132,14 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
132
132
  end
133
133
  end
134
134
  end
135
+ =end
135
136
  end
136
137
 
137
138
  context "after instantiation" do
138
139
  setup do
139
140
  @mongodb_logger = MongodbLogger::Logger.new
140
141
  common_setup
141
- @mongodb_logger.reset_collection
142
+ reset_collection
142
143
  end
143
144
 
144
145
  context "upon insertion of a log record when active record is not used" do
@@ -150,7 +151,7 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
150
151
  should_contain_one_log_record
151
152
 
152
153
  should "allow recreation of the capped collection to remove all records" do
153
- @mongodb_logger.reset_collection
154
+ reset_collection
154
155
  assert_equal 0, @collection.count
155
156
  end
156
157
  end
@@ -207,7 +208,7 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
207
208
  end
208
209
  @mongodb_logger = MongodbLogger::Logger.new
209
210
  common_setup
210
- @mongodb_logger.reset_collection
211
+ reset_collection
211
212
  end
212
213
 
213
214
  should "should not call callback function on log" do
@@ -227,7 +228,7 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
227
228
  setup do
228
229
  @mongodb_logger = MongodbLogger::Logger.new(:level => MongodbLogger::Logger::INFO)
229
230
  common_setup
230
- @mongodb_logger.reset_collection
231
+ reset_collection
231
232
  log("INFO")
232
233
  end
233
234
 
@@ -287,13 +288,13 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
287
288
  FileUtils.cp(file_path, File.join(CONFIG_DIR, DEFAULT_CONFIG))
288
289
  @mongodb_logger = MongodbLogger::Logger.new
289
290
  common_setup
290
- @mongodb_logger.reset_collection
291
+ reset_collection
291
292
 
292
293
  @file_config = YAML.load(ERB.new(File.new(file_path).read).result)[Rails.env]['mongodb_logger']
293
294
  end
294
295
 
295
296
  should "changed collection name" do
296
- assert_equal @file_config['collection'], @mongodb_logger.mongo_collection_name
297
+ assert_equal @file_config['collection'], @collection.name
297
298
  assert_equal "#{@file_config['database']}.#{@file_config['collection']}", @collection.stats()['ns']
298
299
  end
299
300