debug_logging 3.1.8 → 4.0.0
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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +160 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +191 -98
- data/SECURITY.md +16 -0
- data/lib/debug_logging/active_support_notifications.rb +4 -6
- data/lib/debug_logging/argument_printer.rb +105 -89
- data/lib/debug_logging/class_logger.rb +21 -19
- data/lib/debug_logging/class_notifier.rb +18 -22
- data/lib/debug_logging/configuration.rb +21 -23
- data/lib/debug_logging/constants.rb +3 -5
- data/lib/debug_logging/finalize.rb +1 -3
- data/lib/debug_logging/hooks.rb +22 -26
- data/lib/debug_logging/instance_logger.rb +23 -17
- data/lib/debug_logging/instance_logger_modulizer.rb +51 -47
- data/lib/debug_logging/instance_notifier.rb +18 -16
- data/lib/debug_logging/instance_notifier_modulizer.rb +37 -39
- data/lib/debug_logging/log_subscriber.rb +6 -7
- data/lib/debug_logging/util.rb +19 -13
- data/lib/debug_logging/version.rb +3 -3
- data/lib/debug_logging.rb +53 -37
- data/lib/simple_debug_logging.rb +4 -6
- data.tar.gz.sig +0 -0
- metadata +140 -57
- metadata.gz.sig +1 -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,17 @@
|
|
1
|
-
|
1
|
+
require "date"
|
2
|
+
require "time"
|
2
3
|
|
3
4
|
module DebugLogging
|
4
5
|
module ArgumentPrinter
|
5
6
|
def debug_benchmark_to_s(tms:)
|
6
|
-
"completed in #{format(
|
7
|
+
"completed in #{format("%f", tms.real)}s (#{format("%f", tms.total)}s CPU)"
|
7
8
|
end
|
8
9
|
|
9
|
-
def debug_invocation_id_to_s(args: nil, config_proxy: nil)
|
10
|
-
return
|
10
|
+
def debug_invocation_id_to_s(args: nil, kwargs: nil, config_proxy: nil)
|
11
|
+
return "" unless (args || kwargs) && config_proxy
|
11
12
|
|
12
13
|
if config_proxy.debug_add_invocation_id
|
13
|
-
invocation = " ~#{args.object_id}@#{(Time.now.to_f.to_s %
|
14
|
+
invocation = " ~#{args.object_id}|#{kwargs.object_id}@#{(Time.now.to_f.to_s % "%#-21a")[4..-4]}~"
|
14
15
|
case config_proxy.debug_add_invocation_id
|
15
16
|
when true
|
16
17
|
invocation
|
@@ -18,32 +19,51 @@ module DebugLogging
|
|
18
19
|
config_proxy.debug_add_invocation_id.call(ColorizedString[invocation])
|
19
20
|
end
|
20
21
|
else
|
21
|
-
|
22
|
+
""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def debug_time_to_s(time_or_monotonic)
|
27
|
+
# Time format must match:
|
28
|
+
# \d{4,}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4}
|
29
|
+
# YYYY-MM-DD HH:mm:ss +00:00
|
30
|
+
# strftime("%F %T %z")
|
31
|
+
case time_or_monotonic
|
32
|
+
when Float
|
33
|
+
Time.at(time_or_monotonic).strftime("%F %T %z")
|
34
|
+
when Time, DateTime
|
35
|
+
time_or_monotonic.strftime("%F %T %z")
|
36
|
+
when String
|
37
|
+
Time.parse(time_or_monotonic).strftime("%F %T %z")
|
38
|
+
else
|
39
|
+
time_or_monotonic
|
22
40
|
end
|
23
41
|
end
|
24
42
|
|
25
43
|
def debug_invocation_to_s(klass: nil, separator: nil, method_to_log: nil, config_proxy: nil)
|
26
|
-
return
|
44
|
+
return "" unless config_proxy
|
27
45
|
|
28
46
|
klass_string = if config_proxy.debug_colorized_chain_for_class
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
47
|
+
config_proxy.debug_colorized_chain_for_class.call(ColorizedString[klass.to_s])
|
48
|
+
else
|
49
|
+
klass.to_s
|
50
|
+
end
|
33
51
|
method_string = if config_proxy.debug_colorized_chain_for_method
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
52
|
+
config_proxy.debug_colorized_chain_for_method.call(ColorizedString[method_to_log.to_s])
|
53
|
+
else
|
54
|
+
method_to_log.to_s
|
55
|
+
end
|
38
56
|
"#{klass_string}#{separator}#{method_string}"
|
39
57
|
end
|
40
58
|
|
41
|
-
def debug_signature_to_s(args: nil, config_proxy: nil) # rubocop:disable Metrics/CyclomaticComplexity
|
42
|
-
return
|
59
|
+
def debug_signature_to_s(args: nil, kwargs: nil, config_proxy: nil) # rubocop:disable Metrics/CyclomaticComplexity
|
60
|
+
return "" unless (args || kwargs) && config_proxy
|
43
61
|
|
44
|
-
printed_args =
|
62
|
+
printed_args = ""
|
45
63
|
|
46
64
|
add_args_ellipsis = false
|
65
|
+
args = args.dup
|
66
|
+
args.push(kwargs) if kwargs
|
47
67
|
if config_proxy.debug_last_hash_to_s_proc && args[-1].is_a?(Hash)
|
48
68
|
add_other_args_ellipsis = false
|
49
69
|
if args.length > 1
|
@@ -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
|
|
@@ -1,18 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
2
|
module ClassLogger
|
5
3
|
def logged(*methods_to_log)
|
6
4
|
methods_to_log, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
7
5
|
method_names: methods_to_log,
|
8
6
|
payload: nil,
|
9
|
-
config: nil
|
7
|
+
config: nil,
|
10
8
|
)
|
11
9
|
Array(methods_to_log).each do |method_to_log|
|
12
10
|
method_to_log, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
13
11
|
method_names: method_to_log,
|
14
12
|
payload: payload,
|
15
|
-
config: config_opts
|
13
|
+
config: config_opts,
|
16
14
|
)
|
17
15
|
original_method = method(method_to_log)
|
18
16
|
(class << self; self; end).class_eval do
|
@@ -21,16 +19,20 @@ module DebugLogging
|
|
21
19
|
scope: self,
|
22
20
|
config_opts: method_config_opts,
|
23
21
|
method_name: method_to_log,
|
24
|
-
proxy_ref:
|
22
|
+
proxy_ref: "kl",
|
25
23
|
)
|
26
24
|
method_return_value = nil
|
27
25
|
log_prefix = nil
|
28
26
|
invocation_id = nil
|
29
27
|
begin
|
30
28
|
config_proxy.log do
|
31
|
-
paydirt = DebugLogging::Util.
|
32
|
-
log_prefix = debug_invocation_to_s(
|
33
|
-
|
29
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
30
|
+
log_prefix = debug_invocation_to_s(
|
31
|
+
klass: to_s,
|
32
|
+
separator: "::",
|
33
|
+
method_to_log: method_to_log,
|
34
|
+
config_proxy: config_proxy,
|
35
|
+
)
|
34
36
|
invocation_id = debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
|
35
37
|
signature = debug_signature_to_s(args: args, config_proxy: config_proxy)
|
36
38
|
paymud = debug_payload_to_s(payload: paydirt, config_proxy: config_proxy)
|
@@ -39,20 +41,20 @@ module DebugLogging
|
|
39
41
|
if config_proxy.benchmarkable_for?(:debug_class_benchmarks)
|
40
42
|
tms = Benchmark.measure do
|
41
43
|
method_return_value = if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
original_method.call(**harsh, &block)
|
45
|
+
else
|
46
|
+
original_method.call(*args, &block)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
config_proxy.log do
|
48
50
|
"#{log_prefix} #{debug_benchmark_to_s(tms: tms)}#{invocation_id}"
|
49
51
|
end
|
50
52
|
else
|
51
53
|
method_return_value = if args.size == 1 && (harsh = args[0]) && harsh.is_a?(Hash)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
original_method.call(**harsh, &block)
|
55
|
+
else
|
56
|
+
original_method.call(*args, &block)
|
57
|
+
end
|
56
58
|
if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
57
59
|
config_proxy.log do
|
58
60
|
"#{log_prefix} completed#{invocation_id}"
|
@@ -60,11 +62,11 @@ module DebugLogging
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
method_return_value
|
63
|
-
rescue =>
|
65
|
+
rescue StandardError => e
|
64
66
|
if config_proxy.error_handler_proc
|
65
|
-
config_proxy.error_handler_proc.call(config_proxy,
|
67
|
+
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_log, args)
|
66
68
|
else
|
67
|
-
raise
|
69
|
+
raise e
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
@@ -1,18 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
2
|
module ClassNotifier
|
5
|
-
def
|
3
|
+
def notified(*methods_to_notify)
|
6
4
|
methods_to_notify, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
7
5
|
method_names: methods_to_notify,
|
8
6
|
payload: nil,
|
9
|
-
config: nil
|
7
|
+
config: nil,
|
10
8
|
)
|
11
9
|
Array(methods_to_notify).each do |method_to_notify|
|
12
10
|
method_to_notify, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
13
11
|
method_names: method_to_notify,
|
14
12
|
payload: payload,
|
15
|
-
config: config_opts
|
13
|
+
config: config_opts,
|
16
14
|
)
|
17
15
|
original_method = method(method_to_notify)
|
18
16
|
(class << self; self; end).class_eval do
|
@@ -21,37 +19,35 @@ module DebugLogging
|
|
21
19
|
scope: self,
|
22
20
|
config_opts: method_config_opts,
|
23
21
|
method_name: method_to_notify,
|
24
|
-
proxy_ref:
|
22
|
+
proxy_ref: "kn",
|
25
23
|
) do |proxy|
|
26
24
|
ActiveSupport::Notifications.subscribe(
|
27
|
-
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify: method_to_notify)
|
25
|
+
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify: method_to_notify),
|
28
26
|
) do |*debug_args|
|
29
27
|
proxy.log do
|
30
28
|
DebugLogging::LogSubscriber.log_event(ActiveSupport::Notifications::Event.new(*debug_args))
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
34
|
-
paydirt = DebugLogging::Util.
|
32
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
35
33
|
ActiveSupport::Notifications.instrument(
|
36
34
|
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify: method_to_notify),
|
37
35
|
{
|
38
36
|
debug_args: args,
|
39
37
|
config_proxy: config_proxy,
|
40
|
-
**paydirt
|
41
|
-
}
|
38
|
+
**paydirt,
|
39
|
+
},
|
42
40
|
) do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
raise error
|
54
|
-
end
|
41
|
+
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
|
+
rescue StandardError => e
|
47
|
+
if config_proxy.error_handler_proc
|
48
|
+
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_notify, args)
|
49
|
+
else
|
50
|
+
raise e
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
2
|
class Configuration
|
5
3
|
include Constants
|
@@ -11,21 +9,20 @@ module DebugLogging
|
|
11
9
|
# alias the readers to the debug_* prefix so an instance of this class
|
12
10
|
# can have the same API granted by `extend DebugLogging`
|
13
11
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
12
|
+
# extend DebugLogging::InstanceLogger
|
13
|
+
# i_logged [:drive, :stop],
|
14
|
+
# {
|
15
|
+
# logger: Logger.new(STDOUT) # probably want to override to be the Rails.logger
|
16
|
+
# log_level: :debug # at what level do the messages created by this gem sent at?
|
17
|
+
# last_hash_to_s_proc: nil # e.g. ->(hash) { "keys: #{hash.keys}" }
|
18
|
+
# last_hash_max_length: 1_000
|
19
|
+
# args_to_s_proc: nil # e.g. ->(*record) { "record id: #{record.first.id}" }
|
20
|
+
# args_max_length: 1_000
|
21
|
+
# instance_benchmarks: false
|
22
|
+
# class_benchmarks: false
|
23
|
+
# add_invocation_id: true # invocation id allows you to identify a method call uniquely in a log
|
24
|
+
# ellipsis: " ✂️ …".freeze
|
27
25
|
# }
|
28
|
-
# )
|
29
26
|
#
|
30
27
|
CONFIG_KEYS.each do |key|
|
31
28
|
alias_method :"debug_#{key}", :"#{key}"
|
@@ -39,12 +36,13 @@ module DebugLogging
|
|
39
36
|
"@debug_logging_config_#{type}_#{Digest::MD5.hexdigest(method_to_log.to_s)}".to_sym
|
40
37
|
end
|
41
38
|
end
|
39
|
+
|
42
40
|
def initialize(**options)
|
43
41
|
CONFIG_ATTRS.each do |key|
|
44
|
-
send("#{key}=", get_attr_from_options(options, key))
|
42
|
+
send(:"#{key}=", get_attr_from_options(options, key))
|
45
43
|
end
|
46
44
|
CONFIG_READERS.each do |key|
|
47
|
-
send("#{key}=", get_reader_from_options(options, key))
|
45
|
+
send(:"#{key}=", get_reader_from_options(options, key))
|
48
46
|
end
|
49
47
|
@methods_to_log = []
|
50
48
|
end
|
@@ -63,7 +61,7 @@ module DebugLogging
|
|
63
61
|
def loggable?
|
64
62
|
return @loggable if defined?(@loggable)
|
65
63
|
|
66
|
-
@loggable = logger.send("#{log_level}?")
|
64
|
+
@loggable = logger.send(:"#{log_level}?")
|
67
65
|
end
|
68
66
|
|
69
67
|
def benchmarkable_for?(benchmarks)
|
@@ -79,23 +77,23 @@ module DebugLogging
|
|
79
77
|
end
|
80
78
|
|
81
79
|
def instance_benchmarks=(instance_benchmarks)
|
82
|
-
require
|
80
|
+
require "benchmark" if instance_benchmarks
|
83
81
|
@instance_benchmarks = instance_benchmarks
|
84
82
|
end
|
85
83
|
|
86
84
|
def class_benchmarks=(class_benchmarks)
|
87
|
-
require
|
85
|
+
require "benchmark" if class_benchmarks
|
88
86
|
@class_benchmarks = class_benchmarks
|
89
87
|
end
|
90
88
|
|
91
89
|
def active_support_notifications=(active_support_notifications)
|
92
|
-
require
|
90
|
+
require "debug_logging/active_support_notifications" if active_support_notifications
|
93
91
|
@active_support_notifications = active_support_notifications
|
94
92
|
end
|
95
93
|
|
96
94
|
def to_hash
|
97
95
|
CONFIG_KEYS.each_with_object({}) do |key, hash|
|
98
|
-
hash[key] = instance_variable_get("@#{key}")
|
96
|
+
hash[key] = instance_variable_get(:"@#{key}")
|
99
97
|
end
|
100
98
|
end
|
101
99
|
|
@@ -1,8 +1,6 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
2
|
module Constants
|
5
|
-
DEFAULT_ELLIPSIS =
|
3
|
+
DEFAULT_ELLIPSIS = " ✂️ …"
|
6
4
|
CONFIG_ATTRS_DEFAULTS = {
|
7
5
|
enabled: true,
|
8
6
|
logger: Logger.new($stdout),
|
@@ -19,13 +17,13 @@ module DebugLogging
|
|
19
17
|
mark_scope_exit: false,
|
20
18
|
add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
|
21
19
|
payload_max_length: 1_000,
|
22
|
-
error_handler_proc: nil
|
20
|
+
error_handler_proc: nil,
|
23
21
|
}.freeze
|
24
22
|
CONFIG_ATTRS = CONFIG_ATTRS_DEFAULTS.keys
|
25
23
|
CONFIG_READERS_DEFAULTS = {
|
26
24
|
instance_benchmarks: false,
|
27
25
|
class_benchmarks: false,
|
28
|
-
active_support_notifications: false
|
26
|
+
active_support_notifications: false,
|
29
27
|
}.freeze
|
30
28
|
CONFIG_READERS = CONFIG_READERS_DEFAULTS.keys
|
31
29
|
CONFIG_KEYS = CONFIG_ATTRS + CONFIG_READERS
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
# From: https://stackoverflow.com/a/34559282
|
4
2
|
# License: https://creativecommons.org/licenses/by-sa/4.0/
|
5
3
|
module DebugLogging
|
@@ -10,7 +8,7 @@ module DebugLogging
|
|
10
8
|
if obj.respond_to?(:debug_finalize)
|
11
9
|
obj.debug_finalize
|
12
10
|
else
|
13
|
-
warn
|
11
|
+
warn("#{obj} does not define a debug_finalize")
|
14
12
|
end
|
15
13
|
t.disable
|
16
14
|
end
|