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
@@ -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="
|
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='#
|
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 '
|
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
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
73
|
-
@
|
22
|
+
|
23
|
+
def mongo_adapter
|
24
|
+
@logger.mongo_adapter if @logger
|
74
25
|
end
|
75
26
|
end
|
76
27
|
end
|
data/mongodb_logger.gemspec
CHANGED
@@ -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 "
|
15
|
-
gem.add_development_dependency "
|
16
|
-
gem.add_development_dependency "
|
17
|
-
gem.add_development_dependency "
|
18
|
-
gem.add_development_dependency "
|
19
|
-
gem.add_development_dependency "
|
20
|
-
gem.add_development_dependency "uglifier"
|
21
|
-
gem.add_development_dependency "
|
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.
|
24
|
-
gem.
|
25
|
-
gem.
|
26
|
-
gem.
|
27
|
-
gem.
|
28
|
-
gem.
|
29
|
-
gem.
|
30
|
-
gem.
|
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("
|
7
|
+
describe("logInfoPadding", function() {
|
8
8
|
it("should be 15", function() {
|
9
|
-
expect(MongodbLoggerMain.
|
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
|
-
-
|
15
|
-
-
|
16
|
-
-
|
17
|
-
-
|
18
|
-
-
|
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
data/test/test.sh
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/bin/bash
|
2
|
-
|
3
|
-
|
4
|
-
rake
|
5
|
-
|
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 '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
@
|
75
|
-
@
|
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
|
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
|
87
|
-
@
|
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.
|
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
|
-
|
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
|
-
|
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', @
|
88
|
-
assert_equal 27017, @
|
89
|
-
assert_equal MongodbLogger::Logger::DEFAULT_COLLECTION_SIZE, @
|
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", @
|
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", @
|
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 @
|
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", @
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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'], @
|
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
|
|