mongodb_logger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +20 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +17 -0
  4. data/Gemfile +4 -0
  5. data/README.md +177 -0
  6. data/Rakefile +110 -0
  7. data/SUPPORTED_RAILS_VERSIONS +13 -0
  8. data/TESTING.md +24 -0
  9. data/bin/mongodb_logger_web +24 -0
  10. data/config.ru +16 -0
  11. data/examples/server_config.yml +4 -0
  12. data/features/rails.feature +10 -0
  13. data/features/step_definitions/rails_application_steps.rb +48 -0
  14. data/features/support/env.rb +15 -0
  15. data/features/support/rails.rb +91 -0
  16. data/features/support/terminal.rb +94 -0
  17. data/lib/mongodb_logger.rb +31 -0
  18. data/lib/mongodb_logger/initializer_mixin.rb +26 -0
  19. data/lib/mongodb_logger/logger.rb +184 -0
  20. data/lib/mongodb_logger/railtie.rb +12 -0
  21. data/lib/mongodb_logger/replica_set_helper.rb +19 -0
  22. data/lib/mongodb_logger/server.rb +136 -0
  23. data/lib/mongodb_logger/server/model/filter.rb +37 -0
  24. data/lib/mongodb_logger/server/partials.rb +24 -0
  25. data/lib/mongodb_logger/server/public/images/ajax-loader.gif +0 -0
  26. data/lib/mongodb_logger/server/public/images/failure.png +0 -0
  27. data/lib/mongodb_logger/server/public/images/logo.png +0 -0
  28. data/lib/mongodb_logger/server/public/images/play-icon.png +0 -0
  29. data/lib/mongodb_logger/server/public/images/stop-icon.png +0 -0
  30. data/lib/mongodb_logger/server/public/images/success.png +0 -0
  31. data/lib/mongodb_logger/server/public/javascripts/jquery-1.7.min.js +4 -0
  32. data/lib/mongodb_logger/server/public/stylesheets/all.css +9 -0
  33. data/lib/mongodb_logger/server/public/stylesheets/grids.css +18 -0
  34. data/lib/mongodb_logger/server/public/stylesheets/group-buttons.css +83 -0
  35. data/lib/mongodb_logger/server/public/stylesheets/group-forms.css +60 -0
  36. data/lib/mongodb_logger/server/public/stylesheets/group-headers.css +8 -0
  37. data/lib/mongodb_logger/server/public/stylesheets/group-tables.css +42 -0
  38. data/lib/mongodb_logger/server/public/stylesheets/layout.css +168 -0
  39. data/lib/mongodb_logger/server/public/stylesheets/library.css +134 -0
  40. data/lib/mongodb_logger/server/public/stylesheets/reset.css +43 -0
  41. data/lib/mongodb_logger/server/public/stylesheets/spaces.css +42 -0
  42. data/lib/mongodb_logger/server/views/application.coffee +54 -0
  43. data/lib/mongodb_logger/server/views/error.erb +2 -0
  44. data/lib/mongodb_logger/server/views/layout.erb +32 -0
  45. data/lib/mongodb_logger/server/views/overview.erb +94 -0
  46. data/lib/mongodb_logger/server/views/shared/_log.erb +8 -0
  47. data/lib/mongodb_logger/server/views/shared/_log_info.erb +25 -0
  48. data/lib/mongodb_logger/server/views/shared/_tabs.erb +4 -0
  49. data/lib/mongodb_logger/server/views/show_log.erb +85 -0
  50. data/lib/mongodb_logger/server_config.rb +45 -0
  51. data/lib/mongodb_logger/version.rb +3 -0
  52. data/mongodb_logger.gemspec +37 -0
  53. data/test/active_record.rb +13 -0
  54. data/test/config/samples/database.yml +9 -0
  55. data/test/config/samples/database_no_file_logging.yml +10 -0
  56. data/test/config/samples/database_replica_set.yml +8 -0
  57. data/test/config/samples/database_with_auth.yml +9 -0
  58. data/test/config/samples/mongodb_logger.yml +2 -0
  59. data/test/config/samples/mongoid.yml +30 -0
  60. data/test/rails.rb +22 -0
  61. data/test/rails/app/controllers/order_controller.rb +20 -0
  62. data/test/rails/test/functional/order_controller_test.rb +56 -0
  63. data/test/rails/test/test_helper.rb +10 -0
  64. data/test/shoulda_macros/log_macros.rb +13 -0
  65. data/test/test.sh +4 -0
  66. data/test/test_helper.rb +88 -0
  67. data/test/unit/mongodb_logger_replica_test.rb +45 -0
  68. data/test/unit/mongodb_logger_test.rb +252 -0
  69. metadata +300 -0
@@ -0,0 +1,32 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>MongoDB logger</title>
5
+ <link href="<%=u 'stylesheets/all.css' %>" media="screen" rel="stylesheet" type="text/css">
6
+ <script src="<%=u 'javascripts/jquery-1.7.min.js' %>" type="text/javascript"></script>
7
+ <script src="<%=u 'application.js' %>" type="text/javascript"></script>
8
+ </head>
9
+ <body>
10
+ <div class="page">
11
+ <div class="header">
12
+ <div class="wrapper">
13
+ <a href="<%=h url_path("overview") %>" class="logo"><img src="<%=u 'images/logo.png'%>" alt="MongoDB Logger"></a> <span class="logger ">logger</span>
14
+ </div> <!-- wrapper -->
15
+ </div> <!-- header -->
16
+ <div class="content">
17
+ <div class="wrapper">
18
+ <div class="mainbox">
19
+ <%= yield %>
20
+ </div> <!-- mainbox -->
21
+ </div> <!-- wrapper -->
22
+ </div> <!-- content -->
23
+
24
+ <div class="footer">
25
+ <div class="wrapper">
26
+ <p>Text</p>
27
+ </div> <!-- wrapper -->
28
+ </div> <!-- footer -->
29
+ </div>
30
+
31
+ </body>
32
+ </html>
@@ -0,0 +1,94 @@
1
+ <div class="topline">
2
+ <%= partial(:"shared/tabs") %>
3
+ <div class="unit-right">
4
+ <div id="tail_logs_block">
5
+ <div class="initial">
6
+ <a id="tail_logs_link" href="#" data-url="<%=h url_path("tail_logs") %>" class="button mts mrs">
7
+ <span class="start" data-url="<%=h url_path("tail_logs") %>">Tail</span>
8
+ </a>
9
+ </div>
10
+ <div class="info">
11
+ <span id="tail_logs_time"></span>
12
+ <a id="tail_logs_stop_link" href="#" class="button negative mts mrs">
13
+ <span class="stop">Stop</span>
14
+ </a>
15
+ </div>
16
+ </div>
17
+ </div> <!-- unit-right -->
18
+ </div> <!-- topline -->
19
+
20
+ <div class="outer">
21
+ <div class="unit size3of4">
22
+ <div class="filter phm pvs">
23
+ <form action="<%=h url_path("overview") %>" method="get" accept-charset="UTF-8">
24
+ <div class="outer mvs">
25
+ <div class="unit size1of3">
26
+ <div class="unit size1of2">
27
+ <div class="prm">
28
+ <input id="f_controller" type="text" name="f[controller]" value="<%=get_field_val('controller')%>" placeholder="Controller" />
29
+ </div> <!-- prm -->
30
+ </div>
31
+ <div class="unit size1of2">
32
+ <div class="prm">
33
+ <input id="f_action" type="text" name="f[action]" value="<%=get_field_val('action')%>" placeholder="Action" />
34
+ </div>
35
+ </div>
36
+ </div>
37
+ <div class="unit size1of3">
38
+ <div class="unit size1of2">
39
+ <%=select_tag("f[limit]", [100, 500, 1000, 2000, 5000, 10000], get_field_val('limit'))%>
40
+ </div>
41
+ </div>
42
+ <div class="unit size1of3 txtR">
43
+ <input type="submit" name="submit" value="Filter" class="button primary" />
44
+ <a href="<%=h url_path("overview") %>" class="button small mls">Clear</a>
45
+ </div>
46
+ </div> <!-- outer -->
47
+ <div class="outer mvs">
48
+ <div class="unit size1of3">
49
+ <div class="unit size1of2">
50
+ <div class="prm">
51
+ <input id="f_application_name" type="text" name="f[application_name]" value="<%=get_field_val('application_name')%>" placeholder="Application Name" />
52
+ </div>
53
+ </div>
54
+ <div class="unit size1of2">
55
+ <div class="prm">
56
+ <input id="f_ip" type="text" name="f[ip]" value="<%=get_field_val('ip')%>" placeholder="IP" />
57
+ </div>
58
+ </div>
59
+ </div>
60
+ <div class="unit size1of3">
61
+ <div class="unit size1of2">
62
+ <div class="prm ptxs">
63
+ <input type="checkbox" id="err"><label for="err">Error</label>
64
+ </div>
65
+ </div>
66
+ </div> <!-- unit -->
67
+ </div> <!-- outer -->
68
+ </form>
69
+ </div> <!-- filter -->
70
+
71
+ <div class="filter-toggle">
72
+ Filter
73
+ </div> <!-- filter-toggle -->
74
+ <table id="logs_list">
75
+ <tr>
76
+ <th>Received</th>
77
+ <th>Action</th>
78
+ <th>Controller</th>
79
+ <th>IP</th>
80
+ <th>URL</th>
81
+ <th>Runtime</th>
82
+ </tr>
83
+
84
+ <% @logs.each do |log| %>
85
+ <%= partial(:"shared/log", :object => log) %>
86
+ <% end %>
87
+ </table>
88
+ </div> <!-- unit size3of4 -->
89
+
90
+ <div class="unit size1of4">
91
+ <div id="log_info" class="details">
92
+ </div>
93
+ </div> <!-- unit size1of4 -->
94
+ </div> <!-- outer -->
@@ -0,0 +1,8 @@
1
+ <tr class="log_info" data-url="<%=h url_path("log_info/#{log['_id']}") %>">
2
+ <td><%=h log['request_time']%></td>
3
+ <td><%=h log['controller']%></td>
4
+ <td><%=h log['action']%></td>
5
+ <td><%=h log['ip']%></td>
6
+ <td class="url_log"><%=h log['url']%></td>
7
+ <td><%=h log['runtime']%></td>
8
+ </tr>
@@ -0,0 +1,25 @@
1
+ <div class="pas">
2
+ <div class="unit-right ptxs">
3
+ <a href="<%=h url_path("log/#{log_info['_id']}") %>" target="_blank">Direct Link</a>
4
+ </div> <!-- unit-right -->
5
+ <h2 class="phs mvs"><span class="<%= log_info['is_exception'] ? 'failure' : 'success' %>">Message</span></h2>
6
+ <div class="phs">
7
+ <% if log_info['is_exception'] %>
8
+ Error: <%= log_info['messages']['error'] %>
9
+ <% else %>
10
+ Info: <%= log_info['messages']['info'] %>
11
+ <% end %>
12
+ </div> <!-- phs -->
13
+ <h2 class="phs mtm mbs">URL</h2>
14
+ <div class="phs">
15
+ <%=h log_info['url']%>
16
+ </div> <!-- phs -->
17
+ <h2 class="phs mtm mbs">Received</h2>
18
+ <div class="phs">
19
+ <%=h log_info['request_time']%>
20
+ </div> <!-- phs -->
21
+ <h2 class="phs mtm mbs">IP</h2>
22
+ <div class="phs">
23
+ <%=h log_info['ip']%>
24
+ </div> <!-- phs -->
25
+ </div> <!-- pas -->
@@ -0,0 +1,4 @@
1
+ <ul class="unit">
2
+ <li class="active"><a href="<%=h url_path("overview") %>">Logs</a></li>
3
+ <li><a href="#">Graphs</a></li>
4
+ </ul>
@@ -0,0 +1,85 @@
1
+ <div class="topline">
2
+ <%= partial(:"shared/tabs") %>
3
+ </div> <!-- topline -->
4
+ <div class="unit-right">
5
+ <div class="pam">
6
+ <a href="<%=h url_path("overview") %>">Back</a>
7
+ </div> <!-- pam -->
8
+ </div> <!-- unit-right -->
9
+ <h1 class="pam">Log #<%=h @log['_id'] %></h1>
10
+ <ul class="list">
11
+ <li class="outer pvs phm">
12
+ <div class="unit size1of5">
13
+ <span class="pale">Url:</span>
14
+ </div> <!-- unit -->
15
+ <div class="unit size4of5">
16
+ <%=h @log['url'] %>
17
+ </div> <!-- unit -->
18
+ </li>
19
+ <li class="outer pvs phm">
20
+ <div class="unit size1of5">
21
+ <span class="pale">Controller:</span>
22
+ </div> <!-- unit -->
23
+ <div class="unit size4of5">
24
+ <%=h @log['controller'] %>
25
+ </div> <!-- unit -->
26
+ </li>
27
+ <li class="outer pvs phm">
28
+ <div class="unit size1of5">
29
+ <span class="pale">Action:</span>
30
+ </div> <!-- unit -->
31
+ <div class="unit size4of5">
32
+ <%=h @log['action'] %>
33
+ </div> <!-- unit -->
34
+ </li>
35
+ <li class="outer pvs phm">
36
+ <div class="unit size1of5">
37
+ <span class="pale">IP:</span>
38
+ </div> <!-- unit -->
39
+ <div class="unit size4of5">
40
+ <%=h @log['ip'] %>
41
+ </div> <!-- unit -->
42
+ </li>
43
+ <li class="outer pvs phm">
44
+ <div class="unit size1of5">
45
+ <span class="pale">Runtime:</span>
46
+ </div> <!-- unit -->
47
+ <div class="unit size4of5">
48
+ <%=h @log['runtime'] %> ms
49
+ </div> <!-- unit -->
50
+ </li>
51
+ <li class="outer pvs phm">
52
+ <div class="unit size1of5">
53
+ <span class="pale">Params:</span>
54
+ </div> <!-- unit -->
55
+ <div class="unit size4of5">
56
+ <pre>
57
+ <%=h PP.pp(@log['params'].to_hash, "" ) %>
58
+ </pre>
59
+ </div> <!-- unit -->
60
+ </li>
61
+ <% unless @log['messages']['error'].blank? %>
62
+ <li class="outer pvs phm">
63
+ <div class="unit size1of5">
64
+ <span class="pale">Error message:</span>
65
+ </div> <!-- unit -->
66
+ <div class="unit size4of5">
67
+ <pre>
68
+ <%=h @log['messages']['error'].join("\n") %>
69
+ </pre>
70
+ </div> <!-- unit -->
71
+ </li>
72
+ <% end %>
73
+ <% unless @log['messages']['info'].blank? %>
74
+ <li class="outer pvs phm">
75
+ <div class="unit size1of5">
76
+ <span class="pale">Info message:</span>
77
+ </div> <!-- unit -->
78
+ <div class="unit size4of5">
79
+ <pre>
80
+ <%=h @log['messages']['info'].join("\n") %>
81
+ </pre>
82
+ </div> <!-- unit -->
83
+ </li>
84
+ <% end %>
85
+ </ul>
@@ -0,0 +1,45 @@
1
+ require 'mongo'
2
+ require 'erb'
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+
6
+ module MongodbLogger
7
+ class ServerConfig
8
+ class << self
9
+ def set_config(config_path)
10
+ if File.file?(config_path)
11
+ config_file = File.new(config_path)
12
+ config = YAML.load(ERB.new(config_file.read).result)
13
+ else
14
+ raise "Config file not found"
15
+ end
16
+
17
+ @db_configuration = {
18
+ 'host' => 'localhost',
19
+ 'port' => 27017}.merge(config)
20
+ @db_configuration["collection"] ||= "production_log"
21
+ @db = Mongo::Connection.new(@db_configuration['host'],
22
+ @db_configuration['port'],
23
+ :auto_reconnect => true).db(@db_configuration['database'])
24
+
25
+ if @db_configuration['username'] && @db_configuration['password']
26
+ @authenticated = @db.authenticate(@db_configuration['username'],
27
+ @db_configuration['password'])
28
+ end
29
+ @collection = @db[@db_configuration["collection"]]
30
+ end
31
+
32
+ def get_config
33
+ @db_configuration
34
+ end
35
+
36
+ def db
37
+ @db
38
+ end
39
+
40
+ def collection
41
+ @collection
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module MongodbLogger
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/mongodb_logger/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alexey Vasiliev"]
6
+ gem.email = ["leopard.not.a@gmail.com"]
7
+ gem.description = %q{MongoDB logger for Rails 3}
8
+ gem.summary = %q{MongoDB logger for Rails 3}
9
+ gem.homepage = ""
10
+
11
+ gem.add_development_dependency "rspec", "~> 2.7.0"
12
+ gem.add_development_dependency "shoulda", ">= 2.0.0"
13
+ gem.add_development_dependency "mocha", "~> 0.10.0"
14
+ gem.add_development_dependency "cucumber", "~> 1.1.2"
15
+
16
+ gem.add_runtime_dependency "rake", "~> 0.9.0"
17
+ gem.add_runtime_dependency "bundler", ">= 1.0.0"
18
+ gem.add_runtime_dependency "mongo", "~> 1.4.0"
19
+ gem.add_runtime_dependency "bson_ext", "~> 1.4.0"
20
+ gem.add_runtime_dependency "i18n", ">= 0.4.1"
21
+ gem.add_runtime_dependency "json", "~> 1.6.1"
22
+ gem.add_runtime_dependency "activesupport", ">= 3.0.0"
23
+ gem.add_runtime_dependency "sinatra", ">= 1.2.0"
24
+ gem.add_runtime_dependency "erubis", ">= 2.6.6"
25
+ gem.add_runtime_dependency "coffee-script", "~> 2.2.0"
26
+ gem.add_runtime_dependency "vegas", "~> 0.1.2"
27
+
28
+ gem.rubyforge_project = "mongodb_logger"
29
+
30
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
31
+ gem.files = `git ls-files`.split("\n")
32
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
33
+ gem.name = "mongodb_logger"
34
+ gem.require_paths = ["lib"]
35
+ gem.version = MongodbLogger::VERSION
36
+ gem.platform = Gem::Platform::RUBY
37
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecord
2
+ class LogSubscriber
3
+ def self.colorize_logging
4
+ true
5
+ end
6
+ end
7
+
8
+ class Base
9
+ def self.colorize_logging
10
+ true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+ mongodb_logger:
7
+ database: system_log
8
+ application_name: mongo_foo
9
+ safe_insert: true
@@ -0,0 +1,10 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+ mongodb_logger:
7
+ database: system_log
8
+ application_name: mongo_foo
9
+ safe_insert: true
10
+ disable_file_logging: true
@@ -0,0 +1,8 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+ mongodb_logger:
7
+ database: system_log
8
+ replica_set: true
@@ -0,0 +1,9 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+ mongodb_logger:
7
+ database: system_log
8
+ username: admin
9
+ password: password
@@ -0,0 +1,2 @@
1
+ test:
2
+ database: system_log
@@ -0,0 +1,30 @@
1
+ # taken from http://mongoid.org/docs/installation/
2
+ defaults: &defaults
3
+ host: localhost
4
+ slaves:
5
+ - host: slave1.local
6
+ port: 27018
7
+ - host: slave2.local
8
+ port: 27019
9
+ autocreate_indexes: false
10
+ allow_dynamic_fields: true
11
+ include_root_in_json: false
12
+ parameterize_keys: true
13
+ persist_in_safe_mode: false
14
+ raise_not_found_error: true
15
+ reconnect_time: 3
16
+
17
+ development:
18
+ <<: *defaults
19
+ database: control_development
20
+
21
+ test:
22
+ <<: *defaults
23
+ database: system_log
24
+
25
+ # set these environment variables on your prod server
26
+ production:
27
+ <<: *defaults
28
+ host: <%= ENV['MONGOID_HOST'] %>
29
+ port: <%= ENV['MONGOID_PORT'] %>
30
+ database: <%= ENV['MONGOID_DATABASE'] %>
data/test/rails.rb ADDED
@@ -0,0 +1,22 @@
1
+ module MongodbLogger
2
+ class Application
3
+ end
4
+ end
5
+
6
+ class Rails
7
+ module VERSION
8
+ MAJOR = 3
9
+ end
10
+
11
+ def self.env
12
+ ActiveSupport::StringInquirer.new("test")
13
+ end
14
+
15
+ def self.root
16
+ Pathname.new(File.dirname(__FILE__))
17
+ end
18
+
19
+ def self.application
20
+ MongodbLogger::Application.new
21
+ end
22
+ end