debug_logging 3.1.8 → 3.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CONTRIBUTING.md +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +150 -74
- data/SECURITY.md +16 -0
- data/lib/debug_logging/active_support_notifications.rb +4 -4
- data/lib/debug_logging/argument_printer.rb +102 -86
- data/lib/debug_logging/class_logger.rb +21 -17
- data/lib/debug_logging/class_notifier.rb +10 -10
- data/lib/debug_logging/configuration.rb +4 -4
- data/lib/debug_logging/constants.rb +3 -3
- data/lib/debug_logging/finalize.rb +1 -1
- data/lib/debug_logging/hooks.rb +11 -11
- data/lib/debug_logging/instance_logger.rb +5 -3
- data/lib/debug_logging/instance_logger_modulizer.rb +13 -9
- data/lib/debug_logging/instance_notifier.rb +5 -3
- data/lib/debug_logging/instance_notifier_modulizer.rb +13 -9
- data/lib/debug_logging/log_subscriber.rb +6 -5
- data/lib/debug_logging/util.rb +18 -13
- data/lib/debug_logging/version.rb +3 -1
- data/lib/debug_logging.rb +24 -15
- data/lib/simple_debug_logging.rb +3 -3
- data.tar.gz.sig +0 -0
- metadata +153 -55
- metadata.gz.sig +0 -0
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -13
- data/.rspec +0 -2
- data/.rubocop.yml +0 -107
- data/.rubocop_todo.yml +0 -167
- data/.travis.yml +0 -36
- data/Gemfile +0 -12
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/debug_logging.gemspec +0 -42
@@ -1,16 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "date"
|
4
|
+
require "time"
|
5
|
+
|
3
6
|
module DebugLogging
|
4
7
|
module ArgumentPrinter
|
5
8
|
def debug_benchmark_to_s(tms:)
|
6
|
-
"completed in #{format(
|
9
|
+
"completed in #{format("%f", tms.real)}s (#{format("%f", tms.total)}s CPU)"
|
7
10
|
end
|
8
11
|
|
9
12
|
def debug_invocation_id_to_s(args: nil, config_proxy: nil)
|
10
|
-
return
|
13
|
+
return "" unless args && config_proxy
|
11
14
|
|
12
15
|
if config_proxy.debug_add_invocation_id
|
13
|
-
invocation = " ~#{args.object_id}@#{(Time.now.to_f.to_s %
|
16
|
+
invocation = " ~#{args.object_id}@#{(Time.now.to_f.to_s % "%#-21a")[4..-4]}~"
|
14
17
|
case config_proxy.debug_add_invocation_id
|
15
18
|
when true
|
16
19
|
invocation
|
@@ -18,30 +21,47 @@ module DebugLogging
|
|
18
21
|
config_proxy.debug_add_invocation_id.call(ColorizedString[invocation])
|
19
22
|
end
|
20
23
|
else
|
21
|
-
|
24
|
+
""
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def debug_time_to_s(time_or_monotonic)
|
29
|
+
# Time format must match:
|
30
|
+
# \d{4,}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4}
|
31
|
+
# YYYY-MM-DD HH:mm:ss +00:00
|
32
|
+
# strftime("%F %T %z")
|
33
|
+
case time_or_monotonic
|
34
|
+
when Float
|
35
|
+
Time.at(time_or_monotonic).strftime("%F %T %z")
|
36
|
+
when Time, DateTime
|
37
|
+
time_or_monotonic.strftime("%F %T %z")
|
38
|
+
when String
|
39
|
+
Time.parse(time_or_monotonic).strftime("%F %T %z")
|
40
|
+
else
|
41
|
+
time_or_monotonic
|
22
42
|
end
|
23
43
|
end
|
24
44
|
|
25
45
|
def debug_invocation_to_s(klass: nil, separator: nil, method_to_log: nil, config_proxy: nil)
|
26
|
-
return
|
46
|
+
return "" unless config_proxy
|
27
47
|
|
28
48
|
klass_string = if config_proxy.debug_colorized_chain_for_class
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
49
|
+
config_proxy.debug_colorized_chain_for_class.call(ColorizedString[klass.to_s])
|
50
|
+
else
|
51
|
+
klass.to_s
|
52
|
+
end
|
33
53
|
method_string = if config_proxy.debug_colorized_chain_for_method
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
54
|
+
config_proxy.debug_colorized_chain_for_method.call(ColorizedString[method_to_log.to_s])
|
55
|
+
else
|
56
|
+
method_to_log.to_s
|
57
|
+
end
|
38
58
|
"#{klass_string}#{separator}#{method_string}"
|
39
59
|
end
|
40
60
|
|
41
61
|
def debug_signature_to_s(args: nil, config_proxy: nil) # rubocop:disable Metrics/CyclomaticComplexity
|
42
|
-
return
|
62
|
+
return "" unless args && config_proxy
|
43
63
|
|
44
|
-
printed_args =
|
64
|
+
printed_args = ""
|
45
65
|
|
46
66
|
add_args_ellipsis = false
|
47
67
|
if config_proxy.debug_last_hash_to_s_proc && args[-1].is_a?(Hash)
|
@@ -52,18 +72,18 @@ module DebugLogging
|
|
52
72
|
arg.is_a?(Hash)
|
53
73
|
end
|
54
74
|
other_args_string = if config_proxy.debug_args_to_s_proc
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
75
|
+
printed, add_other_args_ellipsis = debug_safe_proc(
|
76
|
+
proc_name: "args_to_s_proc",
|
77
|
+
proc: config_proxy.debug_args_to_s_proc,
|
78
|
+
args: other_args,
|
79
|
+
max_length: config_proxy.debug_args_max_length,
|
80
|
+
)
|
81
|
+
printed
|
82
|
+
else
|
83
|
+
other_args.map(&:inspect).join(", ").tap do |x|
|
84
|
+
add_other_args_ellipsis = x.length > config_proxy.debug_args_max_length
|
85
|
+
end[0..(config_proxy.debug_args_max_length)]
|
86
|
+
end
|
67
87
|
other_args_string += config_proxy.debug_ellipsis if add_other_args_ellipsis
|
68
88
|
# On the debug_multiple_last_hashes truthy branch we don't print the ellipsis after regular args
|
69
89
|
# because it will go instead after each of the last hashes (if needed)
|
@@ -71,73 +91,73 @@ module DebugLogging
|
|
71
91
|
last_hash_args_string = last_hash_args.map do |arg|
|
72
92
|
arr = []
|
73
93
|
printed, add_last_hash_ellipsis = debug_safe_proc(
|
74
|
-
proc_name:
|
94
|
+
proc_name: "last_hash_to_s_proc",
|
75
95
|
proc: config_proxy.debug_last_hash_to_s_proc,
|
76
96
|
args: arg,
|
77
|
-
max_length: config_proxy.debug_last_hash_max_length
|
97
|
+
max_length: config_proxy.debug_last_hash_max_length,
|
78
98
|
)
|
79
99
|
printed += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
80
100
|
arr << printed
|
81
101
|
arr
|
82
|
-
end.flatten.join(
|
102
|
+
end.flatten.join(", ")
|
83
103
|
printed_args += other_args_string if other_args_string
|
84
|
-
printed_args +=
|
104
|
+
printed_args += ", " if !other_args_string.empty? && !last_hash_args_string.empty?
|
85
105
|
printed_args += last_hash_args_string if last_hash_args_string && !last_hash_args_string.empty?
|
86
106
|
else
|
87
107
|
other_args = args[0..-2]
|
88
108
|
other_args_string = if config_proxy.debug_args_to_s_proc
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
109
|
+
printed, add_other_args_ellipsis = debug_safe_proc(
|
110
|
+
proc_name: "args_to_s_proc",
|
111
|
+
proc: config_proxy.debug_args_to_s_proc,
|
112
|
+
args: other_args,
|
113
|
+
max_length: config_proxy.debug_args_max_length,
|
114
|
+
)
|
115
|
+
printed
|
116
|
+
else
|
117
|
+
other_args.map(&:inspect).join(", ").tap do |x|
|
118
|
+
add_other_args_ellipsis = x.length > config_proxy.debug_args_max_length
|
119
|
+
end[0..(config_proxy.debug_args_max_length)]
|
120
|
+
end
|
101
121
|
other_args_string += config_proxy.debug_ellipsis if add_other_args_ellipsis
|
102
122
|
printed_args += other_args_string
|
103
123
|
printed, add_last_hash_ellipsis = debug_safe_proc(
|
104
|
-
proc_name:
|
124
|
+
proc_name: "last_hash_to_s_proc",
|
105
125
|
proc: config_proxy.debug_last_hash_to_s_proc,
|
106
126
|
args: args[-1],
|
107
|
-
max_length: config_proxy.debug_last_hash_max_length
|
127
|
+
max_length: config_proxy.debug_last_hash_max_length,
|
108
128
|
)
|
109
129
|
printed_args += ", #{printed}"
|
110
130
|
printed_args += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
111
131
|
end
|
112
132
|
else
|
113
133
|
printed, add_last_hash_ellipsis = debug_safe_proc(
|
114
|
-
proc_name:
|
134
|
+
proc_name: "last_hash_to_s_proc",
|
115
135
|
proc: config_proxy.debug_last_hash_to_s_proc,
|
116
136
|
args: args[0],
|
117
|
-
max_length: config_proxy.debug_last_hash_max_length
|
137
|
+
max_length: config_proxy.debug_last_hash_max_length,
|
118
138
|
)
|
119
139
|
printed_args += printed
|
120
140
|
printed_args += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
121
141
|
end
|
122
142
|
else
|
123
143
|
printed_args += if config_proxy.debug_args_to_s_proc
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
144
|
+
printed, add_args_ellipsis = debug_safe_proc(
|
145
|
+
proc_name: "args_to_s_proc",
|
146
|
+
proc: config_proxy.debug_args_to_s_proc,
|
147
|
+
args: args,
|
148
|
+
max_length: config_proxy.debug_args_max_length,
|
149
|
+
)
|
150
|
+
printed
|
151
|
+
elsif args.length == 1 && args[0].is_a?(Hash)
|
152
|
+
# handle double splat
|
153
|
+
"**#{args.map(&:inspect).join(", ").tap do |x|
|
154
|
+
add_args_ellipsis = x.length > config_proxy.debug_args_max_length
|
155
|
+
end }"[0..(config_proxy.debug_args_max_length)]
|
156
|
+
else
|
157
|
+
args.map(&:inspect).join(", ").tap do |x|
|
158
|
+
add_args_ellipsis = x.length > config_proxy.debug_args_max_length
|
159
|
+
end[0..(config_proxy.debug_args_max_length)]
|
160
|
+
end
|
141
161
|
printed_args += config_proxy.debug_ellipsis if add_args_ellipsis
|
142
162
|
end
|
143
163
|
"(#{printed_args})"
|
@@ -149,34 +169,30 @@ module DebugLogging
|
|
149
169
|
add_ellipsis = false
|
150
170
|
printed = String(proc.call(args)).tap do |x|
|
151
171
|
add_ellipsis = x.length > max_length
|
152
|
-
end[0..
|
153
|
-
|
154
|
-
rescue => e
|
155
|
-
|
172
|
+
end[0..max_length]
|
173
|
+
[printed, add_ellipsis]
|
174
|
+
rescue StandardError => e
|
175
|
+
["#{e.class}: #{e.message}\nPlease check that your #{proc_name} is able to handle #{args}", false]
|
156
176
|
end
|
157
177
|
end
|
158
178
|
|
159
179
|
def debug_payload_to_s(payload: nil, config_proxy: nil)
|
160
|
-
return
|
180
|
+
return "" unless payload && config_proxy
|
161
181
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
payload.inspect
|
166
|
-
else
|
167
|
-
printed_payload = ""
|
168
|
-
printed, add_payload_ellipsis = debug_safe_proc(
|
169
|
-
proc_name: "add_payload",
|
170
|
-
proc: config_proxy.debug_add_payload,
|
171
|
-
args: payload,
|
172
|
-
max_length: config_proxy.payload_max_length
|
173
|
-
)
|
174
|
-
printed_payload += printed
|
175
|
-
printed_payload += config_proxy.debug_ellipsis if add_payload_ellipsis
|
176
|
-
printed_payload
|
177
|
-
end
|
182
|
+
case config_proxy.debug_add_payload
|
183
|
+
when true
|
184
|
+
payload.inspect
|
178
185
|
else
|
179
|
-
|
186
|
+
printed_payload = ""
|
187
|
+
printed, add_payload_ellipsis = debug_safe_proc(
|
188
|
+
proc_name: "add_payload",
|
189
|
+
proc: config_proxy.debug_add_payload,
|
190
|
+
args: payload,
|
191
|
+
max_length: config_proxy.payload_max_length,
|
192
|
+
)
|
193
|
+
printed_payload += printed
|
194
|
+
printed_payload += config_proxy.debug_ellipsis if add_payload_ellipsis
|
195
|
+
printed_payload
|
180
196
|
end
|
181
197
|
end
|
182
198
|
|
@@ -6,13 +6,13 @@ module DebugLogging
|
|
6
6
|
methods_to_log, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
7
7
|
method_names: methods_to_log,
|
8
8
|
payload: nil,
|
9
|
-
config: nil
|
9
|
+
config: nil,
|
10
10
|
)
|
11
11
|
Array(methods_to_log).each do |method_to_log|
|
12
12
|
method_to_log, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
13
13
|
method_names: method_to_log,
|
14
14
|
payload: payload,
|
15
|
-
config: config_opts
|
15
|
+
config: config_opts,
|
16
16
|
)
|
17
17
|
original_method = method(method_to_log)
|
18
18
|
(class << self; self; end).class_eval do
|
@@ -21,16 +21,20 @@ module DebugLogging
|
|
21
21
|
scope: self,
|
22
22
|
config_opts: method_config_opts,
|
23
23
|
method_name: method_to_log,
|
24
|
-
proxy_ref:
|
24
|
+
proxy_ref: "kl",
|
25
25
|
)
|
26
26
|
method_return_value = nil
|
27
27
|
log_prefix = nil
|
28
28
|
invocation_id = nil
|
29
29
|
begin
|
30
30
|
config_proxy.log do
|
31
|
-
paydirt = DebugLogging::Util.
|
32
|
-
log_prefix = debug_invocation_to_s(
|
33
|
-
|
31
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
32
|
+
log_prefix = debug_invocation_to_s(
|
33
|
+
klass: to_s,
|
34
|
+
separator: ".",
|
35
|
+
method_to_log: method_to_log,
|
36
|
+
config_proxy: config_proxy,
|
37
|
+
)
|
34
38
|
invocation_id = debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
|
35
39
|
signature = debug_signature_to_s(args: args, config_proxy: config_proxy)
|
36
40
|
paymud = debug_payload_to_s(payload: paydirt, config_proxy: config_proxy)
|
@@ -39,20 +43,20 @@ module DebugLogging
|
|
39
43
|
if config_proxy.benchmarkable_for?(:debug_class_benchmarks)
|
40
44
|
tms = Benchmark.measure do
|
41
45
|
method_return_value = if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
original_method.call(**harsh, &block)
|
47
|
+
else
|
48
|
+
original_method.call(*args, &block)
|
49
|
+
end
|
46
50
|
end
|
47
51
|
config_proxy.log do
|
48
52
|
"#{log_prefix} #{debug_benchmark_to_s(tms: tms)}#{invocation_id}"
|
49
53
|
end
|
50
54
|
else
|
51
55
|
method_return_value = if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
original_method.call(**harsh, &block)
|
57
|
+
else
|
58
|
+
original_method.call(*args, &block)
|
59
|
+
end
|
56
60
|
if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
57
61
|
config_proxy.log do
|
58
62
|
"#{log_prefix} completed#{invocation_id}"
|
@@ -60,11 +64,11 @@ module DebugLogging
|
|
60
64
|
end
|
61
65
|
end
|
62
66
|
method_return_value
|
63
|
-
rescue =>
|
67
|
+
rescue StandardError => e
|
64
68
|
if config_proxy.error_handler_proc
|
65
|
-
config_proxy.error_handler_proc.call(config_proxy,
|
69
|
+
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_log, args)
|
66
70
|
else
|
67
|
-
raise
|
71
|
+
raise e
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
@@ -6,13 +6,13 @@ module DebugLogging
|
|
6
6
|
methods_to_notify, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
7
7
|
method_names: methods_to_notify,
|
8
8
|
payload: nil,
|
9
|
-
config: nil
|
9
|
+
config: nil,
|
10
10
|
)
|
11
11
|
Array(methods_to_notify).each do |method_to_notify|
|
12
12
|
method_to_notify, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
13
13
|
method_names: method_to_notify,
|
14
14
|
payload: payload,
|
15
|
-
config: config_opts
|
15
|
+
config: config_opts,
|
16
16
|
)
|
17
17
|
original_method = method(method_to_notify)
|
18
18
|
(class << self; self; end).class_eval do
|
@@ -21,24 +21,24 @@ module DebugLogging
|
|
21
21
|
scope: self,
|
22
22
|
config_opts: method_config_opts,
|
23
23
|
method_name: method_to_notify,
|
24
|
-
proxy_ref:
|
24
|
+
proxy_ref: "kn",
|
25
25
|
) do |proxy|
|
26
26
|
ActiveSupport::Notifications.subscribe(
|
27
|
-
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify: method_to_notify)
|
27
|
+
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify: method_to_notify),
|
28
28
|
) do |*debug_args|
|
29
29
|
proxy.log do
|
30
30
|
DebugLogging::LogSubscriber.log_event(ActiveSupport::Notifications::Event.new(*debug_args))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
paydirt = DebugLogging::Util.
|
34
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
35
35
|
ActiveSupport::Notifications.instrument(
|
36
36
|
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify: method_to_notify),
|
37
37
|
{
|
38
38
|
debug_args: args,
|
39
39
|
config_proxy: config_proxy,
|
40
|
-
**paydirt
|
41
|
-
}
|
40
|
+
**paydirt,
|
41
|
+
},
|
42
42
|
) do
|
43
43
|
begin
|
44
44
|
if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
|
@@ -46,11 +46,11 @@ module DebugLogging
|
|
46
46
|
else
|
47
47
|
original_method.call(*args, &block)
|
48
48
|
end
|
49
|
-
rescue =>
|
49
|
+
rescue StandardError => e
|
50
50
|
if config_proxy.error_handler_proc
|
51
|
-
config_proxy.error_handler_proc.call(config_proxy,
|
51
|
+
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_notify, args)
|
52
52
|
else
|
53
|
-
raise
|
53
|
+
raise e
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -18,7 +18,7 @@ module DebugLogging
|
|
18
18
|
# log_level: :debug # at what level do the messages created by this gem sent at?
|
19
19
|
# last_hash_to_s_proc: nil # e.g. ->(hash) { "keys: #{hash.keys}" }
|
20
20
|
# last_hash_max_length: 1_000
|
21
|
-
# args_to_s_proc: nil # e.g. ->(record) { "record id: #{record.id}" }
|
21
|
+
# args_to_s_proc: nil # e.g. ->(*record) { "record id: #{record.first.id}" }
|
22
22
|
# args_max_length: 1_000
|
23
23
|
# instance_benchmarks: false
|
24
24
|
# class_benchmarks: false
|
@@ -79,17 +79,17 @@ module DebugLogging
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def instance_benchmarks=(instance_benchmarks)
|
82
|
-
require
|
82
|
+
require "benchmark" if instance_benchmarks
|
83
83
|
@instance_benchmarks = instance_benchmarks
|
84
84
|
end
|
85
85
|
|
86
86
|
def class_benchmarks=(class_benchmarks)
|
87
|
-
require
|
87
|
+
require "benchmark" if class_benchmarks
|
88
88
|
@class_benchmarks = class_benchmarks
|
89
89
|
end
|
90
90
|
|
91
91
|
def active_support_notifications=(active_support_notifications)
|
92
|
-
require
|
92
|
+
require "debug_logging/active_support_notifications" if active_support_notifications
|
93
93
|
@active_support_notifications = active_support_notifications
|
94
94
|
end
|
95
95
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module DebugLogging
|
4
4
|
module Constants
|
5
|
-
DEFAULT_ELLIPSIS =
|
5
|
+
DEFAULT_ELLIPSIS = " ✂️ …"
|
6
6
|
CONFIG_ATTRS_DEFAULTS = {
|
7
7
|
enabled: true,
|
8
8
|
logger: Logger.new($stdout),
|
@@ -19,13 +19,13 @@ module DebugLogging
|
|
19
19
|
mark_scope_exit: false,
|
20
20
|
add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
|
21
21
|
payload_max_length: 1_000,
|
22
|
-
error_handler_proc: nil
|
22
|
+
error_handler_proc: nil,
|
23
23
|
}.freeze
|
24
24
|
CONFIG_ATTRS = CONFIG_ATTRS_DEFAULTS.keys
|
25
25
|
CONFIG_READERS_DEFAULTS = {
|
26
26
|
instance_benchmarks: false,
|
27
27
|
class_benchmarks: false,
|
28
|
-
active_support_notifications: false
|
28
|
+
active_support_notifications: false,
|
29
29
|
}.freeze
|
30
30
|
CONFIG_READERS = CONFIG_READERS_DEFAULTS.keys
|
31
31
|
CONFIG_KEYS = CONFIG_ATTRS + CONFIG_READERS
|
data/lib/debug_logging/hooks.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "debug_logging/errors"
|
2
|
+
require "timeout"
|
3
3
|
|
4
4
|
module DebugLogging
|
5
5
|
module Hooks
|
@@ -21,7 +21,7 @@ module DebugLogging
|
|
21
21
|
meth.bind(self).call(*args, &block)
|
22
22
|
end
|
23
23
|
rescue Timeout::Error
|
24
|
-
error_args = [TimeoutError,
|
24
|
+
error_args = [TimeoutError, "execution expired", caller]
|
25
25
|
raise(*error_args) unless blk
|
26
26
|
|
27
27
|
instance_exec(*error_args, &blk)
|
@@ -33,8 +33,8 @@ module DebugLogging
|
|
33
33
|
def debug_rescue_on_fail(*names, &blk)
|
34
34
|
unless blk
|
35
35
|
raise NoBlockGiven,
|
36
|
-
|
37
|
-
|
36
|
+
".rescue_on_fail must be called with a block",
|
37
|
+
caller
|
38
38
|
end
|
39
39
|
names.each do |name|
|
40
40
|
meth = instance_method(name)
|
@@ -51,12 +51,12 @@ module DebugLogging
|
|
51
51
|
def debug_before(*names, &blk)
|
52
52
|
unless blk
|
53
53
|
raise NoBlockGiven,
|
54
|
-
|
55
|
-
|
54
|
+
".before must be called with a block",
|
55
|
+
caller
|
56
56
|
end
|
57
57
|
names.each do |name|
|
58
58
|
meth = instance_method(name)
|
59
|
-
define_method
|
59
|
+
define_method(name) do |*args, &block|
|
60
60
|
instance_exec(name, *args, block, &blk)
|
61
61
|
meth.bind(self).call(*args, &block)
|
62
62
|
end
|
@@ -66,12 +66,12 @@ module DebugLogging
|
|
66
66
|
def debug_after(*names, &blk)
|
67
67
|
unless blk
|
68
68
|
raise NoBlockGiven,
|
69
|
-
|
70
|
-
|
69
|
+
".after must be called with a block",
|
70
|
+
caller
|
71
71
|
end
|
72
72
|
names.each do |name|
|
73
73
|
meth = instance_method(name)
|
74
|
-
define_method
|
74
|
+
define_method(name) do |*args, &block|
|
75
75
|
result = meth.bind(self).call(*args, &block)
|
76
76
|
instance_exec(result, &blk)
|
77
77
|
end
|
@@ -13,9 +13,11 @@ module DebugLogging
|
|
13
13
|
return unless @instance_methods_to_log
|
14
14
|
|
15
15
|
base.send(:include, ArgumentPrinter)
|
16
|
-
instance_method_logger = DebugLogging::InstanceLoggerModulizer.to_mod(
|
17
|
-
|
18
|
-
|
16
|
+
instance_method_logger = DebugLogging::InstanceLoggerModulizer.to_mod(
|
17
|
+
methods_to_log: @instance_methods_to_log,
|
18
|
+
payload: @payload,
|
19
|
+
config: @config,
|
20
|
+
)
|
19
21
|
base.send(:prepend, instance_method_logger)
|
20
22
|
end
|
21
23
|
end
|
@@ -7,13 +7,13 @@ module DebugLogging
|
|
7
7
|
methods_to_log, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
8
8
|
method_names: Array(methods_to_log),
|
9
9
|
payload: payload,
|
10
|
-
config: config
|
10
|
+
config: config,
|
11
11
|
)
|
12
12
|
Array(methods_to_log).each do |method_to_log|
|
13
13
|
method_to_log, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
14
14
|
method_names: method_to_log,
|
15
15
|
payload: payload,
|
16
|
-
config: config_opts
|
16
|
+
config: config_opts,
|
17
17
|
)
|
18
18
|
define_method(method_to_log) do |*args, &block|
|
19
19
|
method_return_value = nil
|
@@ -21,13 +21,17 @@ module DebugLogging
|
|
21
21
|
scope: self.class,
|
22
22
|
config_opts: method_config_opts,
|
23
23
|
method_name: method_to_log,
|
24
|
-
proxy_ref:
|
24
|
+
proxy_ref: "ilm",
|
25
|
+
)
|
26
|
+
log_prefix = self.class.debug_invocation_to_s(
|
27
|
+
klass: self.class.to_s,
|
28
|
+
separator: "#",
|
29
|
+
method_to_log: method_to_log,
|
30
|
+
config_proxy: config_proxy,
|
25
31
|
)
|
26
|
-
log_prefix = self.class.debug_invocation_to_s(klass: self.class.to_s, separator: '#',
|
27
|
-
method_to_log: method_to_log, config_proxy: config_proxy)
|
28
32
|
invocation_id = self.class.debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
|
29
33
|
config_proxy.log do
|
30
|
-
paydirt = DebugLogging::Util.
|
34
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
31
35
|
signature = self.class.debug_signature_to_s(args: args, config_proxy: config_proxy)
|
32
36
|
paymud = debug_payload_to_s(payload: paydirt, config_proxy: config_proxy)
|
33
37
|
"#{log_prefix}#{signature}#{invocation_id} debug: #{paymud}"
|
@@ -42,11 +46,11 @@ module DebugLogging
|
|
42
46
|
else
|
43
47
|
begin
|
44
48
|
method_return_value = super(*args, &block)
|
45
|
-
rescue =>
|
49
|
+
rescue StandardError => e
|
46
50
|
if config_proxy.error_handler_proc
|
47
|
-
config_proxy.error_handler_proc.call(config_proxy,
|
51
|
+
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_log, args)
|
48
52
|
else
|
49
|
-
raise
|
53
|
+
raise e
|
50
54
|
end
|
51
55
|
end
|
52
56
|
if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
@@ -13,9 +13,11 @@ module DebugLogging
|
|
13
13
|
return unless @instance_methods_to_notify
|
14
14
|
|
15
15
|
base.send(:include, ArgumentPrinter)
|
16
|
-
instance_method_notifier = DebugLogging::InstanceNotifierModulizer.to_mod(
|
17
|
-
|
18
|
-
|
16
|
+
instance_method_notifier = DebugLogging::InstanceNotifierModulizer.to_mod(
|
17
|
+
methods_to_notify: @instance_methods_to_notify,
|
18
|
+
payload: @payload,
|
19
|
+
config: @config,
|
20
|
+
)
|
19
21
|
base.send(:prepend, instance_method_notifier)
|
20
22
|
end
|
21
23
|
end
|