debug_logging 3.1.5 → 3.1.7

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
  SHA256:
3
- metadata.gz: 77770fe7ac99f46e73cbcbc12eeaef1ad69978ab9880ae8758758d203c9e1267
4
- data.tar.gz: 9e09d725eba529f29103468581fb8718eee02946d02a97cbeb444a7df946bfc1
3
+ metadata.gz: 434bf02e4e2e51b0ae6ffb99e4d5174d212a2337744e1fd7697d66d804ccc062
4
+ data.tar.gz: efb30cc90b8d325da9511f6899378b790916ad671af4b69df1b6171aa9cda80e
5
5
  SHA512:
6
- metadata.gz: e26b9a71370c7f87ffc03a202cee289a0510f9e552dba96edd7034fad32f16c6d4b83da7b64d2f4e516d81af0743b3a70f21896f9e08bd87f68c962e8aeb12b9
7
- data.tar.gz: e85efa9c27319c63fc3d9923602ac901eb1ca32ecbe726f0cdd54eec656706426b17a69d3ee2b1bb96f76b8b801569b7b54b544966903f9316603da54c3ff64f
6
+ metadata.gz: 99ec10ad80d3caca7a1092365774530b017a15276515f06b610dfd39e0e3e7f9883f59489d53ac2162b36e6c39371eb115b588524c8c9ed2cd4355b30a61bd89
7
+ data.tar.gz: 9af78b97aed63a43e63c27e998d9c713ece75825bcc91b6be704cf757a289c43b96a106d5ef5bff2783828dfac3bd4d48ae110fcfd3841fb556c88cb64bb9108
data/README.md CHANGED
@@ -42,6 +42,7 @@ Supports ActiveSupport::Notifications (thanks [@jgillson](https://github.com/jgi
42
42
  * *ActiveRecord style callback-hooks (optional: `require 'debug_logging/hooks'` and `include DebugLogging::Hooks`), since v3.1.3*
43
43
  * *All configuration is inheritable to, and overridable by, child classes, since v3.1.3*
44
44
  * *[Class finalization hook](https://stackoverflow.com/a/34559282) (optional: `require 'debug_logging/finalize'` and `extend DebugLogging::Finalize`), since v3.1.3*
45
+ * *Error handling hooks you can use to log problems when they happen, since v3.1.7*
45
46
  * **so many free ponies** 🎠🐴🎠🐴🎠🐴
46
47
 
47
48
  ## Next Level Magic
@@ -50,8 +51,10 @@ Herein you will find:
50
51
 
51
52
  * Classes inheriting from Module
52
53
  * Zero tolerance policy on monkey patching
54
+ * When the gem is loaded there are no monkey patches.
55
+ * Rather, your own classes/methods get "patched" and "hooked" as you configure them.
53
56
  * 100% clean, 0% obtrusive
54
- * 100% tested
57
+ * ~100% tested
55
58
  * 100% Ruby 2.1+ compatible
56
59
  - use version `gem "debug_logging", "~> 1.0"` for Ruby < 2.3
57
60
  - use version `gem "debug_logging", "~> 2.0"` for Ruby 2.3
@@ -95,6 +98,7 @@ DebugLogging.configuration.log_level = :debug # at what level do the messages cr
95
98
  DebugLogging.configuration.multiple_last_hashes = false # pass every hash argument to last_hash_to_s_proc?
96
99
  DebugLogging.configuration.last_hash_to_s_proc = nil # e.g. ->(hash) { "keys: #{hash.keys}" }
97
100
  DebugLogging.configuration.last_hash_max_length = 1_000
101
+ DebugLogging.configuration.args_to_s_proc = nil # e.g. ->(record) { "record id: #{record.id}" }
98
102
  DebugLogging.configuration.args_max_length = 1_000
99
103
  DebugLogging.configuration.instance_benchmarks = false
100
104
  DebugLogging.configuration.class_benchmarks = false
@@ -104,6 +108,9 @@ DebugLogging.configuration.colorized_chain_for_class = false # e.g. ->(colorized
104
108
  DebugLogging.configuration.add_invocation_id = true # identify a method call uniquely in a log, pass a proc for colorization, e.g. ->(colorized_string) { colorized_string.light_black }
105
109
  DebugLogging.configuration.ellipsis = ' ✂️ …'.freeze
106
110
  DebugLogging.configuration.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
111
+ DebugLogging.configuration.add_payload = false # or a proc which will be called to print the payload
112
+ DebugLogging.configuration.payload_max_length = 1000
113
+ DebugLogging.configuration.error_handler_proc = nil # e.g. ->(error, config, obj) { config.log { "#{error.class}: #{error.message}\n#{obj.errors.inspect}" } }
107
114
  ```
108
115
 
109
116
  If you prefer to use the block style:
@@ -115,6 +122,7 @@ DebugLogging.configure do |config|
115
122
  config.multiple_last_hashes = false # pass every hash argument to last_hash_to_s_proc?
116
123
  config.last_hash_to_s_proc = nil # e.g. ->(hash) { "keys: #{hash.keys}" }
117
124
  config.last_hash_max_length = 1_000
125
+ config.args_to_s_proc = nil # e.g. ->(record) { "record id: #{record.id}" }
118
126
  config.args_max_length = 1_000
119
127
  config.instance_benchmarks = false
120
128
  config.class_benchmarks = false
@@ -124,6 +132,9 @@ DebugLogging.configure do |config|
124
132
  config.add_invocation_id = true # identify a method call uniquely in a log, pass a proc for colorization, e.g. ->(colorized_string) { colorized_string.light_black }
125
133
  config.ellipsis = ' ✂️ …'.freeze
126
134
  config.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
135
+ config.add_payload = false # or a proc which will be called to print the payload
136
+ config.payload_max_length = 1000
137
+ config.error_handler_proc = nil # e.g. ->(error, config, obj) { config.log { "#{error.class}: #{error.message}\n#{obj.errors.inspect}" } }
127
138
  end
128
139
  ```
129
140
 
@@ -4,6 +4,7 @@ require 'logger'
4
4
  require 'colorized_string'
5
5
  require 'digest'
6
6
 
7
+ require 'debug_logging/constants'
7
8
  require 'debug_logging/version'
8
9
  require 'debug_logging/errors'
9
10
  require 'debug_logging/configuration'
@@ -64,6 +65,8 @@ require 'debug_logging/class_logger'
64
65
  module DebugLogging
65
66
  def self.extended(base)
66
67
  base.send(:extend, ArgumentPrinter)
68
+ base.send(:extend, ApiClassMethods)
69
+ base.send(:extend, ConfigClassMethods)
67
70
  base.debug_config_reset(Configuration.new(**debug_logging_configuration.to_hash))
68
71
  base.class_eval do
69
72
  def base.inherited(subclass)
@@ -73,22 +76,6 @@ module DebugLogging
73
76
  end
74
77
 
75
78
  #### API ####
76
- # Not used by this gem internally, but provides an external interface for
77
- # classes to also use this logging tool directly,
78
- # with configured options like benchmarking, colors, or leg level.
79
- def debug_log(message = nil, config_proxy = nil, &block)
80
- # If a, instance-method-level, or class-method-level custom config is not
81
- # passed in, then fall back to the class' default config, which is a
82
- # potentially customized copy of the default config for the whole app.
83
- config_proxy ||= debug_config
84
- config_proxy.log(message, &block)
85
- end
86
-
87
- # There are times when the class will need access to the configuration object,
88
- # such as to override it per instance method
89
- def debug_config
90
- @debug_logging_configuration
91
- end
92
79
 
93
80
  # For single statement global config in an initializer
94
81
  # e.g. DebugLogging.configuration.ellipsis = "..."
@@ -101,138 +88,187 @@ module DebugLogging
101
88
  yield(configuration)
102
89
  end
103
90
 
104
- # For per-class config with a block
105
- def debug_logging_configure
106
- @debug_logging_configuration ||= Configuration.new
107
- yield(@debug_logging_configuration)
91
+ module ApiClassMethods
92
+ # Not used by this gem internally, but provides an external interface for
93
+ # classes to also use this logging tool directly,
94
+ # with configured options like benchmarking, colors, or leg level.
95
+ def debug_log(message = nil, config_proxy = nil, &block)
96
+ # If a, instance-method-level, or class-method-level custom config is not
97
+ # passed in, then fall back to the class' default config, which is a
98
+ # potentially customized copy of the default config for the whole app.
99
+ config_proxy ||= debug_config
100
+ config_proxy.log(message, &block)
101
+ end
102
+
103
+ # There are times when the class will need access to the configuration object,
104
+ # such as to override it per instance method
105
+ def debug_config
106
+ @debug_logging_configuration
107
+ end
108
108
  end
109
109
 
110
110
  #### CONFIG ####
111
111
  class << self
112
112
  attr_accessor :debug_logging_configuration
113
113
  end
114
- def debug_config_reset(config = Configuration.new)
115
- @debug_logging_configuration = config
116
- end
117
114
 
118
- def debug_enabled
119
- @debug_logging_configuration.enabled
120
- end
115
+ module ConfigClassMethods
116
+ include Constants
121
117
 
122
- def debug_enabled=(value)
123
- @debug_logging_configuration.enabled = value
124
- end
118
+ # For per-class config with a block
119
+ def debug_logging_configure
120
+ @debug_logging_configuration ||= Configuration.new
121
+ yield(@debug_logging_configuration)
122
+ end
125
123
 
126
- def debug_logger
127
- @debug_logging_configuration.logger
128
- end
124
+ def debug_config_reset(config = Configuration.new)
125
+ @debug_logging_configuration = config
126
+ end
129
127
 
130
- def debug_logger=(logger)
131
- @debug_logging_configuration.logger = logger
132
- end
128
+ def debug_enabled
129
+ @debug_logging_configuration.enabled
130
+ end
133
131
 
134
- def debug_log_level
135
- @debug_logging_configuration.log_level
136
- end
132
+ def debug_enabled=(value)
133
+ @debug_logging_configuration.enabled = value
134
+ end
137
135
 
138
- def debug_log_level=(log_level)
139
- @debug_logging_configuration.log_level = log_level
140
- end
136
+ def debug_logger
137
+ @debug_logging_configuration.logger
138
+ end
141
139
 
142
- def debug_multiple_last_hashes
143
- @debug_logging_configuration.multiple_last_hashes
144
- end
140
+ def debug_logger=(logger)
141
+ @debug_logging_configuration.logger = logger
142
+ end
145
143
 
146
- def debug_multiple_last_hashes=(multiple_last_hashes)
147
- @debug_logging_configuration.multiple_last_hashes = multiple_last_hashes
148
- end
144
+ def debug_log_level
145
+ @debug_logging_configuration.log_level
146
+ end
149
147
 
150
- def debug_last_hash_to_s_proc
151
- @debug_logging_configuration.last_hash_to_s_proc
152
- end
148
+ def debug_log_level=(log_level)
149
+ @debug_logging_configuration.log_level = log_level
150
+ end
153
151
 
154
- def debug_last_hash_to_s_proc=(last_hash_to_s_proc)
155
- @debug_logging_configuration.last_hash_to_s_proc = last_hash_to_s_proc
156
- end
152
+ def debug_multiple_last_hashes
153
+ @debug_logging_configuration.multiple_last_hashes
154
+ end
157
155
 
158
- def debug_last_hash_max_length
159
- @debug_logging_configuration.last_hash_max_length
160
- end
156
+ def debug_multiple_last_hashes=(multiple_last_hashes)
157
+ @debug_logging_configuration.multiple_last_hashes = multiple_last_hashes
158
+ end
161
159
 
162
- def debug_last_hash_max_length=(last_hash_max_length)
163
- @debug_logging_configuration.last_hash_max_length = last_hash_max_length
164
- end
160
+ def debug_last_hash_to_s_proc
161
+ @debug_logging_configuration.last_hash_to_s_proc
162
+ end
165
163
 
166
- def debug_args_to_s_proc
167
- @debug_logging_configuration.args_to_s_proc
168
- end
164
+ def debug_last_hash_to_s_proc=(last_hash_to_s_proc)
165
+ @debug_logging_configuration.last_hash_to_s_proc = last_hash_to_s_proc
166
+ end
169
167
 
170
- def debug_args_to_s_proc=(args_to_s_proc)
171
- @debug_logging_configuration.args_to_s_proc = args_to_s_proc
172
- end
168
+ def debug_last_hash_max_length
169
+ @debug_logging_configuration.last_hash_max_length
170
+ end
173
171
 
174
- def debug_args_max_length
175
- @debug_logging_configuration.args_max_length
176
- end
172
+ def debug_last_hash_max_length=(last_hash_max_length)
173
+ @debug_logging_configuration.last_hash_max_length = last_hash_max_length
174
+ end
177
175
 
178
- def debug_args_max_length=(args_max_length)
179
- @debug_logging_configuration.args_max_length = args_max_length
180
- end
176
+ def debug_args_to_s_proc
177
+ @debug_logging_configuration.args_to_s_proc
178
+ end
181
179
 
182
- def debug_instance_benchmarks
183
- @debug_logging_configuration.instance_benchmarks
184
- end
180
+ def debug_args_to_s_proc=(args_to_s_proc)
181
+ @debug_logging_configuration.args_to_s_proc = args_to_s_proc
182
+ end
185
183
 
186
- def debug_instance_benchmarks=(instance_benchmarks)
187
- @debug_logging_configuration.instance_benchmarks = instance_benchmarks
188
- end
184
+ def debug_args_max_length
185
+ @debug_logging_configuration.args_max_length
186
+ end
189
187
 
190
- def debug_class_benchmarks
191
- @debug_logging_configuration.class_benchmarks
192
- end
188
+ def debug_args_max_length=(args_max_length)
189
+ @debug_logging_configuration.args_max_length = args_max_length
190
+ end
193
191
 
194
- def debug_class_benchmarks=(class_benchmarks)
195
- @debug_logging_configuration.class_benchmarks = class_benchmarks
196
- end
192
+ def debug_instance_benchmarks
193
+ @debug_logging_configuration.instance_benchmarks
194
+ end
197
195
 
198
- def debug_colorized_chain_for_method
199
- @debug_logging_configuration.colorized_chain_for_method
200
- end
196
+ def debug_instance_benchmarks=(instance_benchmarks)
197
+ @debug_logging_configuration.instance_benchmarks = instance_benchmarks
198
+ end
201
199
 
202
- def debug_colorized_chain_for_method=(colorized_chain_for_method)
203
- @debug_logging_configuration.colorized_chain_for_method = colorized_chain_for_method
204
- end
200
+ def debug_class_benchmarks
201
+ @debug_logging_configuration.class_benchmarks
202
+ end
205
203
 
206
- def debug_colorized_chain_for_class
207
- @debug_logging_configuration.colorized_chain_for_class
208
- end
204
+ def debug_class_benchmarks=(class_benchmarks)
205
+ @debug_logging_configuration.class_benchmarks = class_benchmarks
206
+ end
209
207
 
210
- def debug_colorized_chain_for_class=(colorized_chain_for_class)
211
- @debug_logging_configuration.colorized_chain_for_class = colorized_chain_for_class
212
- end
208
+ def debug_colorized_chain_for_method
209
+ @debug_logging_configuration.colorized_chain_for_method
210
+ end
213
211
 
214
- def debug_add_invocation_id
215
- @debug_logging_configuration.add_invocation_id
216
- end
212
+ def debug_colorized_chain_for_method=(colorized_chain_for_method)
213
+ @debug_logging_configuration.colorized_chain_for_method = colorized_chain_for_method
214
+ end
217
215
 
218
- def debug_add_invocation_id=(add_invocation_id)
219
- @debug_logging_configuration.add_invocation_id = add_invocation_id
220
- end
216
+ def debug_colorized_chain_for_class
217
+ @debug_logging_configuration.colorized_chain_for_class
218
+ end
221
219
 
222
- def debug_mark_scope_exit
223
- @debug_logging_configuration.mark_scope_exit
224
- end
220
+ def debug_colorized_chain_for_class=(colorized_chain_for_class)
221
+ @debug_logging_configuration.colorized_chain_for_class = colorized_chain_for_class
222
+ end
225
223
 
226
- def debug_mark_scope_exit=(mark_scope_exit)
227
- @debug_logging_configuration.mark_scope_exit = mark_scope_exit
228
- end
224
+ def debug_add_invocation_id
225
+ @debug_logging_configuration.add_invocation_id
226
+ end
229
227
 
230
- def debug_ellipsis
231
- @debug_logging_configuration.ellipsis
232
- end
228
+ def debug_add_invocation_id=(add_invocation_id)
229
+ @debug_logging_configuration.add_invocation_id = add_invocation_id
230
+ end
231
+
232
+ def debug_ellipsis
233
+ @debug_logging_configuration.ellipsis
234
+ end
235
+
236
+ def debug_ellipsis=(ellipsis)
237
+ @debug_logging_configuration.ellipsis = ellipsis
238
+ end
239
+
240
+ def debug_mark_scope_exit
241
+ @debug_logging_configuration.mark_scope_exit
242
+ end
243
+
244
+ def debug_mark_scope_exit=(mark_scope_exit)
245
+ @debug_logging_configuration.mark_scope_exit = mark_scope_exit
246
+ end
247
+
248
+ def debug_add_payload
249
+ @debug_logging_configuration.add_payload
250
+ end
233
251
 
234
- def debug_ellipsis=(ellipsis)
235
- @debug_logging_configuration.ellipsis = ellipsis
252
+ def debug_add_payload=(add_payload)
253
+ @debug_logging_configuration.add_payload = add_payload
254
+ end
255
+
256
+ def debug_payload_max_length
257
+ @debug_logging_configuration.payload_max_length
258
+ end
259
+
260
+ def debug_payload_max_length=(payload_max_length)
261
+ @debug_logging_configuration.payload_max_length = payload_max_length
262
+ end
263
+
264
+ def debug_error_handler_proc
265
+ @debug_logging_configuration.error_handler_proc
266
+ end
267
+
268
+ def debug_error_handler_proc=(error_handler_proc)
269
+ @debug_logging_configuration.error_handler_proc = error_handler_proc
270
+ end
236
271
  end
272
+
237
273
  self.debug_logging_configuration = Configuration.new # setup defaults
238
274
  end
@@ -26,39 +26,47 @@ module DebugLogging
26
26
  method_return_value = nil
27
27
  log_prefix = nil
28
28
  invocation_id = nil
29
- config_proxy.log do
30
- paydirt = DebugLogging::Util.payload_instance_vaiable_hydration(scope: self, payload: method_payload)
31
- log_prefix = debug_invocation_to_s(klass: to_s, separator: '.', method_to_log: method_to_log,
32
- config_proxy: config_proxy)
33
- invocation_id = debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
34
- signature = debug_signature_to_s(args: args, config_proxy: config_proxy)
35
- paymud = debug_payload_to_s(payload: paydirt, config_proxy: config_proxy)
36
- "#{log_prefix}#{signature}#{invocation_id} debug: #{paymud}"
37
- end
38
- if config_proxy.benchmarkable_for?(:debug_class_benchmarks)
39
- tms = Benchmark.measure do
29
+ begin
30
+ config_proxy.log do
31
+ paydirt = DebugLogging::Util.payload_instance_vaiable_hydration(scope: self, payload: method_payload)
32
+ log_prefix = debug_invocation_to_s(klass: to_s, separator: '.', method_to_log: method_to_log,
33
+ config_proxy: config_proxy)
34
+ invocation_id = debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
35
+ signature = debug_signature_to_s(args: args, config_proxy: config_proxy)
36
+ paymud = debug_payload_to_s(payload: paydirt, config_proxy: config_proxy)
37
+ "#{log_prefix}#{signature}#{invocation_id} debug: #{paymud}"
38
+ end
39
+ if config_proxy.benchmarkable_for?(:debug_class_benchmarks)
40
+ tms = Benchmark.measure do
41
+ method_return_value = if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
42
+ original_method.call(**harsh, &block)
43
+ else
44
+ original_method.call(*args, &block)
45
+ end
46
+ end
47
+ config_proxy.log do
48
+ "#{log_prefix} #{debug_benchmark_to_s(tms: tms)}#{invocation_id}"
49
+ end
50
+ else
40
51
  method_return_value = if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
41
52
  original_method.call(**harsh, &block)
42
53
  else
43
54
  original_method.call(*args, &block)
44
55
  end
45
- end
46
- config_proxy.log do
47
- "#{log_prefix} #{debug_benchmark_to_s(tms: tms)}#{invocation_id}"
48
- end
49
- else
50
- method_return_value = if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
51
- original_method.call(**harsh, &block)
52
- else
53
- original_method.call(*args, &block)
54
- end
55
- if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
56
- config_proxy.log do
57
- "#{log_prefix} completed#{invocation_id}"
56
+ if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
57
+ config_proxy.log do
58
+ "#{log_prefix} completed#{invocation_id}"
59
+ end
58
60
  end
59
61
  end
62
+ method_return_value
63
+ rescue => error
64
+ if config_proxy.error_handler_proc
65
+ config_proxy.error_handler_proc.call(config_proxy, error, self)
66
+ else
67
+ raise error
68
+ end
60
69
  end
61
- method_return_value
62
70
  end
63
71
  end
64
72
  end
@@ -40,10 +40,18 @@ module DebugLogging
40
40
  **paydirt
41
41
  }
42
42
  ) do
43
- if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
44
- original_method.call(**harsh, &block)
45
- else
46
- original_method.call(*args, &block)
43
+ begin
44
+ if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
45
+ original_method.call(**harsh, &block)
46
+ else
47
+ original_method.call(*args, &block)
48
+ end
49
+ rescue => error
50
+ if config_proxy.error_handler_proc
51
+ config_proxy.error_handler_proc.call(config_proxy, error, self)
52
+ else
53
+ raise error
54
+ end
47
55
  end
48
56
  end
49
57
  end
@@ -2,33 +2,7 @@
2
2
 
3
3
  module DebugLogging
4
4
  class Configuration
5
- DEFAULT_ELLIPSIS = ' ✂️ …'
6
- CONFIG_ATTRS_DEFAULTS = {
7
- enabled: true,
8
- logger: Logger.new($stdout),
9
- log_level: :debug,
10
- multiple_last_hashes: false,
11
- last_hash_to_s_proc: nil,
12
- last_hash_max_length: 1_000,
13
- args_to_s_proc: nil,
14
- args_max_length: 1_000,
15
- colorized_chain_for_method: false,
16
- colorized_chain_for_class: false,
17
- add_invocation_id: true,
18
- ellipsis: DEFAULT_ELLIPSIS,
19
- mark_scope_exit: false,
20
- add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
21
- payload_max_length: 1_000
22
- }.freeze
23
- CONFIG_ATTRS = CONFIG_ATTRS_DEFAULTS.keys
24
- CONFIG_READERS_DEFAULTS = {
25
- instance_benchmarks: false,
26
- class_benchmarks: false,
27
- active_support_notifications: false
28
- }.freeze
29
- CONFIG_READERS = CONFIG_READERS_DEFAULTS.keys
30
- CONFIG_KEYS = CONFIG_ATTRS + CONFIG_READERS
31
-
5
+ include Constants
32
6
  # For reference, log levels as integers mapped to symbols:
33
7
  # LEVELS = { 0 => :debug, 1 => :info, 2 => :warn, 3 => :error, 4 => :fatal, 5 => :unknown }
34
8
  attr_accessor(*CONFIG_ATTRS)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DebugLogging
4
+ module Constants
5
+ DEFAULT_ELLIPSIS = ' ✂️ …'
6
+ CONFIG_ATTRS_DEFAULTS = {
7
+ enabled: true,
8
+ logger: Logger.new($stdout),
9
+ log_level: :debug,
10
+ multiple_last_hashes: false,
11
+ last_hash_to_s_proc: nil,
12
+ last_hash_max_length: 1_000,
13
+ args_to_s_proc: nil,
14
+ args_max_length: 1_000,
15
+ colorized_chain_for_method: false,
16
+ colorized_chain_for_class: false,
17
+ add_invocation_id: true,
18
+ ellipsis: DEFAULT_ELLIPSIS,
19
+ mark_scope_exit: false,
20
+ add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
21
+ payload_max_length: 1_000,
22
+ error_handler_proc: nil
23
+ }.freeze
24
+ CONFIG_ATTRS = CONFIG_ATTRS_DEFAULTS.keys
25
+ CONFIG_READERS_DEFAULTS = {
26
+ instance_benchmarks: false,
27
+ class_benchmarks: false,
28
+ active_support_notifications: false
29
+ }.freeze
30
+ CONFIG_READERS = CONFIG_READERS_DEFAULTS.keys
31
+ CONFIG_KEYS = CONFIG_ATTRS + CONFIG_READERS
32
+ end
33
+ end
@@ -40,7 +40,15 @@ module DebugLogging
40
40
  "#{log_prefix} #{self.class.debug_benchmark_to_s(tms: tms)}#{invocation_id}"
41
41
  end
42
42
  else
43
- method_return_value = super(*args, &block)
43
+ begin
44
+ method_return_value = super(*args, &block)
45
+ rescue => error
46
+ if config_proxy.error_handler_proc
47
+ config_proxy.error_handler_proc.call(config_proxy, error, self)
48
+ else
49
+ raise error
50
+ end
51
+ end
44
52
  if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
45
53
  config_proxy.log do
46
54
  "#{log_prefix} completed#{invocation_id}"
@@ -37,7 +37,15 @@ module DebugLogging
37
37
  config_proxy: config_proxy,
38
38
  **paydirt
39
39
  ) do
40
- super(*args, &block)
40
+ begin
41
+ super(*args, &block)
42
+ rescue => error
43
+ if config_proxy.error_handler_proc
44
+ config_proxy.error_handler_proc.call(config_proxy, error, self)
45
+ else
46
+ raise error
47
+ end
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DebugLogging
4
- VERSION = '3.1.5'
4
+ VERSION = '3.1.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-18 00:00:00.000000000 Z
12
+ date: 2020-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -227,6 +227,7 @@ files:
227
227
  - lib/debug_logging/class_logger.rb
228
228
  - lib/debug_logging/class_notifier.rb
229
229
  - lib/debug_logging/configuration.rb
230
+ - lib/debug_logging/constants.rb
230
231
  - lib/debug_logging/errors.rb
231
232
  - lib/debug_logging/finalize.rb
232
233
  - lib/debug_logging/hooks.rb