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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c85e18e15f0aa46051bdd6d5d6d827ca662fce6b
4
- data.tar.gz: 65889439258e4082571f87310c90a035bf23229d
3
+ metadata.gz: 30f8e8e54923dfdc287aeb35da8c13dd4ab6b49c
4
+ data.tar.gz: fcd753fbf378de1fd0e5c3b2d12592c34bfdbf67
5
5
  SHA512:
6
- metadata.gz: 7b02d897ef866380ce133cd11215f9c974907008aa9d072f549fb7a9652e7511e0b49e7b5326f334c58bd99831d67dc4f795181db8ac3b4ba786b98703a22659
7
- data.tar.gz: 9010d7c2270809e8436b22334f7d36ed864fb7aba114ae51d30873ce3af799358bf80df6167466a440694915f1c4ff4481a8d1e8da88d63035487bb6597a6929
6
+ metadata.gz: 8396dc16368ead80fd6e778acdc4ddf3d1072645ff08699a0caf651c0c58732a3e643ef8a0cb54b1c52ccfb276c1544c9730630f43a5a9e4cccbed31793f49a5
7
+ data.tar.gz: c514903ed15b3bfcc772c352b4edc18227c3c5ab4499d98fba7ab69db1125bc41afe8040d8f8f174e69ed9c2b8e92a4dfd9d2940d892528f782dd258d219c7a7
@@ -1,3 +1,3 @@
1
1
  module TransactionLogger
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -40,12 +40,24 @@ module TransactionLogger
40
40
  transaction.context = options[:context]
41
41
  transaction.context ||= {}
42
42
 
43
- method_info = {}
44
- method_info[:logger_method] = self.class.instance_method :logger
45
- method_info[:calling_method] = caller_locations(1, 1)[0].label
46
- method_info[:includer] = self
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
- includer.class.send :define_method, :logger, lambda {
69
- @original_logger ||= logger_method.bind(includer).call
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
@@ -3,10 +3,77 @@ require "logger"
3
3
 
4
4
  describe TransactionLogger do
5
5
  let (:test_lmbda) {
6
- lambda do |_t|
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.1
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-07-21 00:00:00.000000000 Z
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: