transaction_logger 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/transaction_logger/version.rb +1 -1
- data/lib/transaction_logger.rb +29 -7
- data/spec/transaction_logger/transaction_manager_spec.rb +0 -0
- data/spec/transaction_logger/transaction_spec.rb +0 -0
- data/spec/transaction_logger_configure_spec.rb +0 -0
- data/spec/transaction_logger_helper_spec.rb +0 -0
- data/spec/transaction_logger_spec.rb +68 -1
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30f8e8e54923dfdc287aeb35da8c13dd4ab6b49c
|
|
4
|
+
data.tar.gz: fcd753fbf378de1fd0e5c3b2d12592c34bfdbf67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8396dc16368ead80fd6e778acdc4ddf3d1072645ff08699a0caf651c0c58732a3e643ef8a0cb54b1c52ccfb276c1544c9730630f43a5a9e4cccbed31793f49a5
|
|
7
|
+
data.tar.gz: c514903ed15b3bfcc772c352b4edc18227c3c5ab4499d98fba7ab69db1125bc41afe8040d8f8f174e69ed9c2b8e92a4dfd9d2940d892528f782dd258d219c7a7
|
data/lib/transaction_logger.rb
CHANGED
|
@@ -40,12 +40,24 @@ module TransactionLogger
|
|
|
40
40
|
transaction.context = options[:context]
|
|
41
41
|
transaction.context ||= {}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
# Check for a logger on the instance
|
|
44
|
+
if methods.include? :logger
|
|
45
|
+
logger_method = method(:logger).unbind
|
|
46
|
+
# Check for a logger on the class
|
|
47
|
+
elsif self.class.methods.include? :logger
|
|
48
|
+
logger_method = self.class.method :logger
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Trap the logger if we've found one
|
|
52
|
+
if logger_method
|
|
53
|
+
method_info = {}
|
|
54
|
+
method_info[:logger_method] = logger_method
|
|
55
|
+
method_info[:calling_method] = caller_locations(1, 1)[0].label
|
|
56
|
+
method_info[:includer] = self
|
|
57
|
+
|
|
58
|
+
TransactionLogger::Helper.trap_logger method, transaction, method_info
|
|
59
|
+
end
|
|
47
60
|
|
|
48
|
-
TransactionLogger::Helper.trap_logger method, transaction, method_info
|
|
49
61
|
old_method.bind(self).call
|
|
50
62
|
}
|
|
51
63
|
end
|
|
@@ -65,8 +77,18 @@ module TransactionLogger
|
|
|
65
77
|
calling_method = method_info[:calling_method]
|
|
66
78
|
includer = method_info[:includer]
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
if logger_method.is_a? UnboundMethod
|
|
81
|
+
method_type = :define_method
|
|
82
|
+
else
|
|
83
|
+
method_type = :define_singleton_method
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
includer.class.send method_type, :logger, lambda {
|
|
87
|
+
if logger_method.is_a? UnboundMethod
|
|
88
|
+
@original_logger ||= logger_method.bind(includer).call
|
|
89
|
+
else
|
|
90
|
+
@original_logger ||= logger_method.call
|
|
91
|
+
end
|
|
70
92
|
|
|
71
93
|
@trapped_logger ||= {}
|
|
72
94
|
@trapped_logger[calling_method] ||= LoggerProxy.new @original_logger, transaction
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,10 +3,77 @@ require "logger"
|
|
|
3
3
|
|
|
4
4
|
describe TransactionLogger do
|
|
5
5
|
let (:test_lmbda) {
|
|
6
|
-
lambda
|
|
6
|
+
lambda do |_t|
|
|
7
7
|
end
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
context "Logger trapping" do
|
|
11
|
+
let(:instance_logger) {
|
|
12
|
+
Class.new do
|
|
13
|
+
include TransactionLogger
|
|
14
|
+
|
|
15
|
+
def do_something
|
|
16
|
+
logger.info "TEST"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def logger
|
|
20
|
+
Logger.new STDOUT
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
add_transaction_log :do_something
|
|
24
|
+
end
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let(:klass_logger) {
|
|
28
|
+
Class.new do
|
|
29
|
+
include TransactionLogger
|
|
30
|
+
|
|
31
|
+
def do_something
|
|
32
|
+
self.class.logger.info "TEST"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.logger
|
|
36
|
+
Logger.new STDOUT
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
add_transaction_log :do_something
|
|
40
|
+
end
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let(:no_logger) {
|
|
44
|
+
Class.new do
|
|
45
|
+
include TransactionLogger
|
|
46
|
+
|
|
47
|
+
def do_something
|
|
48
|
+
puts "TEST"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
add_transaction_log :do_something
|
|
52
|
+
end
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
it "supports #logger" do
|
|
56
|
+
expect_any_instance_of(TransactionLogger::LoggerProxy).to receive(:info).and_call_original
|
|
57
|
+
expect_any_instance_of(Logger).to receive(:info).and_call_original
|
|
58
|
+
test = instance_logger.new
|
|
59
|
+
test.do_something
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "supports .logger" do
|
|
63
|
+
expect_any_instance_of(TransactionLogger::LoggerProxy).to receive(:info).and_call_original
|
|
64
|
+
expect_any_instance_of(Logger).to receive(:info).and_call_original
|
|
65
|
+
test = klass_logger.new
|
|
66
|
+
test.do_something
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "supports no logger" do
|
|
70
|
+
expect_any_instance_of(TransactionLogger::LoggerProxy).to_not receive(:info)
|
|
71
|
+
expect_any_instance_of(Logger).to_not receive(:info)
|
|
72
|
+
test = no_logger.new
|
|
73
|
+
test.do_something
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
10
77
|
subject {
|
|
11
78
|
TransactionLogger::Transaction.new(
|
|
12
79
|
{ prefix: nil, logger: Logger.new(STDOUT), level_threshold: nil }, test_lmbda)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: transaction_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Donner
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2015-
|
|
12
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -150,6 +150,10 @@ files:
|
|
|
150
150
|
- lib/transaction_logger/version.rb
|
|
151
151
|
- spec/spec_helper.rb
|
|
152
152
|
- spec/support/debugging.rb
|
|
153
|
+
- spec/transaction_logger/transaction_manager_spec.rb
|
|
154
|
+
- spec/transaction_logger/transaction_spec.rb
|
|
155
|
+
- spec/transaction_logger_configure_spec.rb
|
|
156
|
+
- spec/transaction_logger_helper_spec.rb
|
|
153
157
|
- spec/transaction_logger_spec.rb
|
|
154
158
|
- transaction_logger.gemspec
|
|
155
159
|
homepage: https://github.com/blinkist/transaction_logger
|
|
@@ -179,5 +183,9 @@ summary: Contextual Business Transaction Logger for Ruby
|
|
|
179
183
|
test_files:
|
|
180
184
|
- spec/spec_helper.rb
|
|
181
185
|
- spec/support/debugging.rb
|
|
186
|
+
- spec/transaction_logger/transaction_manager_spec.rb
|
|
187
|
+
- spec/transaction_logger/transaction_spec.rb
|
|
188
|
+
- spec/transaction_logger_configure_spec.rb
|
|
189
|
+
- spec/transaction_logger_helper_spec.rb
|
|
182
190
|
- spec/transaction_logger_spec.rb
|
|
183
191
|
has_rdoc:
|