mongodb_logger 0.2.7-jruby → 0.2.8-jruby
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +11 -0
- data/Rakefile +1 -1
- data/SUPPORTED_RAILS_VERSIONS +2 -1
- data/lib/mongodb_logger/config.rb +32 -0
- data/lib/mongodb_logger/logger.rb +4 -2
- data/lib/mongodb_logger/server_config.rb +1 -1
- data/lib/mongodb_logger/version.rb +1 -1
- data/lib/mongodb_logger.rb +3 -0
- data/test/rails/test/functional/order_controller_test.rb +1 -1
- data/test/unit/mongodb_logger_test.rb +26 -0
- metadata +37 -36
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -104,6 +104,17 @@ It:
|
|
104
104
|
Rails.logger.add_metadata(:user_id => @current_user.id)
|
105
105
|
end
|
106
106
|
|
107
|
+
## Callback on exceptions
|
108
|
+
|
109
|
+
For send email or do something on exception you can add callback:
|
110
|
+
|
111
|
+
MongodbLogger::Base.configure do |config|
|
112
|
+
config.on_log_exception do |mongo_record|
|
113
|
+
# do something with this data, for example - send email (better - by background job)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
In this callback send record without "\_id", because logger not wait for insert response from MongoDB.
|
107
118
|
|
108
119
|
## The Front End
|
109
120
|
To setup web interface in you Rails application, first of all create autoload file in you Rails application
|
data/Rakefile
CHANGED
@@ -79,7 +79,7 @@ if ENV['CI']
|
|
79
79
|
if 'java' == RUBY_PLATFORM
|
80
80
|
RAILS_VERSIONS = ['3.0.11', '3.1.3']
|
81
81
|
else
|
82
|
-
RAILS_VERSIONS = ['3.0.11', '3.1.3', '3.2.
|
82
|
+
RAILS_VERSIONS = ['3.0.11', '3.1.3', '3.2.3']
|
83
83
|
end
|
84
84
|
else
|
85
85
|
RAILS_VERSIONS = IO.read('SUPPORTED_RAILS_VERSIONS').strip.split("\n")
|
data/SUPPORTED_RAILS_VERSIONS
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module MongodbLogger
|
2
|
+
# Change config options in an initializer:
|
3
|
+
#
|
4
|
+
# MongodbLogger::Base.on_log_exception do |mongo_record|
|
5
|
+
# ... call some code ...
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# Or in a block:
|
9
|
+
#
|
10
|
+
# MongodbLogger::Base.configure do |config|
|
11
|
+
# config.on_log_exception do |mongo_record|
|
12
|
+
# ... call some code ...
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
|
16
|
+
module Config
|
17
|
+
attr_accessor :on_log_exception
|
18
|
+
|
19
|
+
def configure
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_log_exception(*args, &block)
|
24
|
+
if block
|
25
|
+
@on_log_exception = block
|
26
|
+
elsif @on_log_exception
|
27
|
+
@on_log_exception.call(*args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -80,6 +80,8 @@ module MongodbLogger
|
|
80
80
|
ensure
|
81
81
|
# In case of exception, make sure runtime is set
|
82
82
|
@mongo_record[:runtime] = ((runtime ||= 0) * 1000).ceil
|
83
|
+
# error callback
|
84
|
+
Base.on_log_exception(@mongo_record) if @mongo_record[:is_exception]
|
83
85
|
begin
|
84
86
|
@insert_block.call
|
85
87
|
rescue
|
@@ -151,12 +153,12 @@ module MongodbLogger
|
|
151
153
|
def mongo_connection_object
|
152
154
|
if @db_configuration['hosts']
|
153
155
|
conn = Mongo::ReplSetConnection.new(*(@db_configuration['hosts'] <<
|
154
|
-
{:
|
156
|
+
{:connect => true, :pool_timeout => 6}))
|
155
157
|
@db_configuration['replica_set'] = true
|
156
158
|
else
|
157
159
|
conn = Mongo::Connection.new(@db_configuration['host'],
|
158
160
|
@db_configuration['port'],
|
159
|
-
:
|
161
|
+
:connect => true,
|
160
162
|
:pool_timeout => 6)
|
161
163
|
end
|
162
164
|
@mongo_connection_type = conn.class
|
@@ -25,7 +25,7 @@ module MongodbLogger
|
|
25
25
|
@db_configuration["collection"] ||= "production_log"
|
26
26
|
@db = Mongo::Connection.new(@db_configuration['host'],
|
27
27
|
@db_configuration['port'],
|
28
|
-
:
|
28
|
+
:connect => true).db(@db_configuration['database'])
|
29
29
|
|
30
30
|
if @db_configuration['username'] && @db_configuration['password']
|
31
31
|
@authenticated = @db.authenticate(@db_configuration['username'],
|
data/lib/mongodb_logger.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
|
3
3
|
require 'mongo'
|
4
|
+
require 'mongodb_logger/config'
|
4
5
|
require 'mongodb_logger/logger'
|
5
6
|
require 'mongodb_logger/railtie' if defined?(Rails::Railtie)
|
6
7
|
require 'mongodb_logger/version'
|
7
8
|
|
8
9
|
module MongodbLogger
|
9
10
|
module Base
|
11
|
+
extend Config
|
12
|
+
|
10
13
|
def self.included(base)
|
11
14
|
base.class_eval { around_filter :enable_mongodb_logger }
|
12
15
|
end
|
@@ -64,7 +64,7 @@ class OrderControllerTest < ActionController::TestCase
|
|
64
64
|
:float => 1.22
|
65
65
|
}
|
66
66
|
|
67
|
-
# such testing down on Rails 3.1.x, because in tests params
|
67
|
+
# such testing down on Rails 3.1.x, because in tests params convert Fixnum values into String
|
68
68
|
# :(
|
69
69
|
# assert_equal 1, @collection.find({"params.data.int" => 1}).count
|
70
70
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'mongodb_logger'
|
2
3
|
require 'mongodb_logger/logger'
|
3
4
|
require 'tempfile'
|
4
5
|
require 'pathname'
|
@@ -183,6 +184,31 @@ class MongodbLogger::LoggerTest < Test::Unit::TestCase
|
|
183
184
|
end
|
184
185
|
end
|
185
186
|
end
|
187
|
+
|
188
|
+
context "after configure" do
|
189
|
+
setup do
|
190
|
+
MongodbLogger::Base.configure do |config|
|
191
|
+
config.on_log_exception do |mongo_record|
|
192
|
+
# do something
|
193
|
+
end
|
194
|
+
end
|
195
|
+
@mongodb_logger = MongodbLogger::Logger.new
|
196
|
+
common_setup
|
197
|
+
@mongodb_logger.reset_collection
|
198
|
+
end
|
199
|
+
|
200
|
+
should "should not call callback function on log" do
|
201
|
+
MongodbLogger::Base.expects(:on_log_exception).times(0)
|
202
|
+
log("Test")
|
203
|
+
end
|
204
|
+
|
205
|
+
context "when an exception is raised" do
|
206
|
+
should "should call callback function" do
|
207
|
+
MongodbLogger::Base.expects(:on_log_exception).times(1)
|
208
|
+
assert_raise(RuntimeError, EXCEPTION_MSG) {log_exception(EXCEPTION_MSG)}
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
186
212
|
|
187
213
|
context "logging at INFO level" do
|
188
214
|
setup do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongodb_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: jruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jasmine
|
16
|
-
requirement: &
|
16
|
+
requirement: &70176175566300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70176175566300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70176175565600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.8.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70176175565600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda
|
38
|
-
requirement: &
|
38
|
+
requirement: &70176175565000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70176175565000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70176175564380 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.10.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70176175564380
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: cucumber
|
60
|
-
requirement: &
|
60
|
+
requirement: &70176175563820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.1.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70176175563820
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: capybara
|
71
|
-
requirement: &
|
71
|
+
requirement: &70176175593020 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.1.2
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70176175593020
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: coffee-script
|
82
|
-
requirement: &
|
82
|
+
requirement: &70176175592240 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 2.2.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70176175592240
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: uglifier
|
93
|
-
requirement: &
|
93
|
+
requirement: &70176175590980 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 1.2.0
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70176175590980
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: rake
|
104
|
-
requirement: &
|
104
|
+
requirement: &70176175590080 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 0.9.0
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70176175590080
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: mongo
|
115
|
-
requirement: &
|
115
|
+
requirement: &70176175589420 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ~>
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 1.6.1
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70176175589420
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: i18n
|
126
|
-
requirement: &
|
126
|
+
requirement: &70176175588660 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: 0.4.1
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70176175588660
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: json
|
137
|
-
requirement: &
|
137
|
+
requirement: &70176175587880 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ~>
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: 1.6.1
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70176175587880
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: activesupport
|
148
|
-
requirement: &
|
148
|
+
requirement: &70176175587140 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: 3.0.0
|
154
154
|
type: :runtime
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70176175587140
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: actionpack
|
159
|
-
requirement: &
|
159
|
+
requirement: &70176175586520 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,10 +164,10 @@ dependencies:
|
|
164
164
|
version: 3.0.0
|
165
165
|
type: :runtime
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *70176175586520
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: sinatra
|
170
|
-
requirement: &
|
170
|
+
requirement: &70176175585820 !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
173
173
|
- - ! '>='
|
@@ -175,10 +175,10 @@ dependencies:
|
|
175
175
|
version: 1.2.0
|
176
176
|
type: :runtime
|
177
177
|
prerelease: false
|
178
|
-
version_requirements: *
|
178
|
+
version_requirements: *70176175585820
|
179
179
|
- !ruby/object:Gem::Dependency
|
180
180
|
name: erubis
|
181
|
-
requirement: &
|
181
|
+
requirement: &70176175624260 !ruby/object:Gem::Requirement
|
182
182
|
none: false
|
183
183
|
requirements:
|
184
184
|
- - ! '>='
|
@@ -186,10 +186,10 @@ dependencies:
|
|
186
186
|
version: 2.6.6
|
187
187
|
type: :runtime
|
188
188
|
prerelease: false
|
189
|
-
version_requirements: *
|
189
|
+
version_requirements: *70176175624260
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
191
|
name: vegas
|
192
|
-
requirement: &
|
192
|
+
requirement: &70176175623420 !ruby/object:Gem::Requirement
|
193
193
|
none: false
|
194
194
|
requirements:
|
195
195
|
- - ~>
|
@@ -197,7 +197,7 @@ dependencies:
|
|
197
197
|
version: 0.1.2
|
198
198
|
type: :runtime
|
199
199
|
prerelease: false
|
200
|
-
version_requirements: *
|
200
|
+
version_requirements: *70176175623420
|
201
201
|
description: MongoDB logger for Rails 3
|
202
202
|
email:
|
203
203
|
- leopard.not.a@gmail.com
|
@@ -229,6 +229,7 @@ files:
|
|
229
229
|
- features/support/rails.rb
|
230
230
|
- features/support/terminal.rb
|
231
231
|
- lib/mongodb_logger.rb
|
232
|
+
- lib/mongodb_logger/config.rb
|
232
233
|
- lib/mongodb_logger/initializer_mixin.rb
|
233
234
|
- lib/mongodb_logger/logger.rb
|
234
235
|
- lib/mongodb_logger/railtie.rb
|