mongo_request_logger 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/mongo_request_logger/adapters/mongo.rb +5 -2
- data/lib/mongo_request_logger/version.rb +1 -1
- data/spec/shared_examples.rb +14 -6
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,9 @@ module MongoRequestLogger
|
|
9
9
|
def initialize(options = {})
|
10
10
|
@authenticated = false
|
11
11
|
@configuration = options.with_indifferent_access
|
12
|
+
@configuration['host'] ||= '127.0.0.1'
|
13
|
+
@configuration['port'] ||= '27017'
|
14
|
+
@configuration['collection'] ||= 'server_log'
|
12
15
|
|
13
16
|
connect
|
14
17
|
|
@@ -54,9 +57,9 @@ module MongoRequestLogger
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def query(criteria, options={})
|
57
|
-
q = @collection.find(
|
60
|
+
q = @collection.find(criteria).sort('timestamp', -1)
|
58
61
|
if options[:limit]
|
59
|
-
q = q.limit(options
|
62
|
+
q = q.limit(options[:limit])
|
60
63
|
end
|
61
64
|
q
|
62
65
|
end
|
data/spec/shared_examples.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
shared_examples "log" do
|
2
2
|
|
3
|
+
let(:logger) { MongoRequestLogger::Logger.new @adapter, @file }
|
3
4
|
|
4
5
|
it "should log without a request" do
|
5
|
-
logger = MongoRequestLogger::Logger.new @adapter, @file
|
6
6
|
logger.info "Test message"
|
7
7
|
logger.error "Test error"
|
8
8
|
logger.close
|
@@ -11,7 +11,7 @@ shared_examples "log" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should log requests" do
|
14
|
-
|
14
|
+
|
15
15
|
options = {test_option: "Test value", args: {"one" => "Value"}}
|
16
16
|
logger.log_request(options) do
|
17
17
|
logger.add_metadata value: "Test"
|
@@ -36,9 +36,20 @@ shared_examples "log" do
|
|
36
36
|
messages[1].should match /ERROR.*Test error/
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should query logs" do
|
40
|
+
logger.log_request(my_number: 5) do
|
41
|
+
logger.info "Test message"
|
42
|
+
end
|
43
|
+
|
44
|
+
logs = @adapter.query({}, limit: 2).to_a
|
45
|
+
logs.count.should == 1
|
46
|
+
log = logs.first
|
47
|
+
log['my_number'].should == 5
|
48
|
+
end
|
49
|
+
|
39
50
|
it "should log exceptions" do
|
40
51
|
class MyError < StandardError; end
|
41
|
-
|
52
|
+
|
42
53
|
options = {test_option: "Test value", args: {"one" => "Value"}}
|
43
54
|
logger.log_request(options) do
|
44
55
|
logger.info "Test message"
|
@@ -59,8 +70,6 @@ shared_examples "log" do
|
|
59
70
|
it "should log raised errors" do
|
60
71
|
class MyError < StandardError; end
|
61
72
|
|
62
|
-
logger = MongoRequestLogger::Logger.new @adapter, @file
|
63
|
-
options = {test_option: "Test value", args: {"one" => "Value"}}
|
64
73
|
block = ->{
|
65
74
|
logger.log_request do
|
66
75
|
logger.info "Test message"
|
@@ -86,7 +95,6 @@ shared_examples "log" do
|
|
86
95
|
infinite_recursion(n+1)
|
87
96
|
end
|
88
97
|
|
89
|
-
logger = MongoRequestLogger::Logger.new @adapter, @file
|
90
98
|
block = ->{
|
91
99
|
logger.log_request do
|
92
100
|
begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_request_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -418,7 +418,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
418
418
|
version: '0'
|
419
419
|
segments:
|
420
420
|
- 0
|
421
|
-
hash:
|
421
|
+
hash: 3718731922470250442
|
422
422
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
423
423
|
none: false
|
424
424
|
requirements:
|
@@ -427,7 +427,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
427
427
|
version: '0'
|
428
428
|
segments:
|
429
429
|
- 0
|
430
|
-
hash:
|
430
|
+
hash: 3718731922470250442
|
431
431
|
requirements: []
|
432
432
|
rubyforge_project:
|
433
433
|
rubygems_version: 1.8.24
|