debug_logging 3.1.4 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/debug_logging.rb +8 -0
- data/lib/debug_logging/argument_printer.rb +86 -23
- data/lib/debug_logging/configuration.rb +4 -1
- data/lib/debug_logging/finalize.rb +1 -1
- data/lib/debug_logging/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77770fe7ac99f46e73cbcbc12eeaef1ad69978ab9880ae8758758d203c9e1267
|
4
|
+
data.tar.gz: 9e09d725eba529f29103468581fb8718eee02946d02a97cbeb444a7df946bfc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e26b9a71370c7f87ffc03a202cee289a0510f9e552dba96edd7034fad32f16c6d4b83da7b64d2f4e516d81af0743b3a70f21896f9e08bd87f68c962e8aeb12b9
|
7
|
+
data.tar.gz: e85efa9c27319c63fc3d9923602ac901eb1ca32ecbe726f0cdd54eec656706426b17a69d3ee2b1bb96f76b8b801569b7b54b544966903f9316603da54c3ff64f
|
data/lib/debug_logging.rb
CHANGED
@@ -163,6 +163,14 @@ module DebugLogging
|
|
163
163
|
@debug_logging_configuration.last_hash_max_length = last_hash_max_length
|
164
164
|
end
|
165
165
|
|
166
|
+
def debug_args_to_s_proc
|
167
|
+
@debug_logging_configuration.args_to_s_proc
|
168
|
+
end
|
169
|
+
|
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
|
173
|
+
|
166
174
|
def debug_args_max_length
|
167
175
|
@debug_logging_configuration.args_max_length
|
168
176
|
end
|
@@ -45,49 +45,90 @@ module DebugLogging
|
|
45
45
|
|
46
46
|
add_args_ellipsis = false
|
47
47
|
if config_proxy.debug_last_hash_to_s_proc && args[-1].is_a?(Hash)
|
48
|
-
|
48
|
+
add_other_args_ellipsis = false
|
49
49
|
if args.length > 1
|
50
50
|
if config_proxy.debug_multiple_last_hashes
|
51
51
|
last_hash_args, other_args = args.partition do |arg|
|
52
52
|
arg.is_a?(Hash)
|
53
53
|
end
|
54
|
-
other_args_string =
|
54
|
+
other_args_string = if config_proxy.debug_args_to_s_proc
|
55
|
+
printed, add_other_args_ellipsis = debug_safe_proc(
|
56
|
+
proc_name:'args_to_s_proc',
|
57
|
+
proc: config_proxy.debug_args_to_s_proc,
|
58
|
+
args: other_args,
|
59
|
+
max_length: config_proxy.debug_args_max_length
|
60
|
+
)
|
61
|
+
printed
|
62
|
+
else
|
63
|
+
other_args.map(&:inspect).join(', ').tap do |x|
|
64
|
+
add_other_args_ellipsis = x.length > config_proxy.debug_args_max_length
|
65
|
+
end[0..(config_proxy.debug_args_max_length)]
|
66
|
+
end
|
67
|
+
other_args_string += config_proxy.debug_ellipsis if add_other_args_ellipsis
|
55
68
|
# On the debug_multiple_last_hashes truthy branch we don't print the ellipsis after regular args
|
56
|
-
# because it will go instead after the last
|
69
|
+
# because it will go instead after each of the last hashes (if needed)
|
57
70
|
# ...join(", ").tap {|x| _add_args_ellipsis = x.length > config_proxy.debug_args_max_length}
|
58
71
|
last_hash_args_string = last_hash_args.map do |arg|
|
59
72
|
arr = []
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
73
|
+
printed, add_last_hash_ellipsis = debug_safe_proc(
|
74
|
+
proc_name:'last_hash_to_s_proc',
|
75
|
+
proc: config_proxy.debug_last_hash_to_s_proc,
|
76
|
+
args: arg,
|
77
|
+
max_length: config_proxy.debug_last_hash_max_length
|
78
|
+
)
|
79
|
+
printed += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
80
|
+
arr << printed
|
68
81
|
arr
|
69
82
|
end.flatten.join(', ')
|
70
83
|
printed_args += other_args_string if other_args_string
|
71
84
|
printed_args += ', ' if !other_args_string.empty? && !last_hash_args_string.empty?
|
72
85
|
printed_args += last_hash_args_string if last_hash_args_string && !last_hash_args_string.empty?
|
73
86
|
else
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
87
|
+
other_args = args[0..-2]
|
88
|
+
other_args_string = if config_proxy.debug_args_to_s_proc
|
89
|
+
printed, add_other_args_ellipsis = debug_safe_proc(
|
90
|
+
proc_name:'args_to_s_proc',
|
91
|
+
proc: config_proxy.debug_args_to_s_proc,
|
92
|
+
args: other_args,
|
93
|
+
max_length: config_proxy.debug_args_max_length
|
94
|
+
)
|
95
|
+
printed
|
96
|
+
else
|
97
|
+
other_args.map(&:inspect).join(', ').tap do |x|
|
98
|
+
add_other_args_ellipsis = x.length > config_proxy.debug_args_max_length
|
99
|
+
end[0..(config_proxy.debug_args_max_length)]
|
100
|
+
end
|
101
|
+
other_args_string += config_proxy.debug_ellipsis if add_other_args_ellipsis
|
102
|
+
printed_args += other_args_string
|
103
|
+
printed, add_last_hash_ellipsis = debug_safe_proc(
|
104
|
+
proc_name:'last_hash_to_s_proc',
|
105
|
+
proc: config_proxy.debug_last_hash_to_s_proc,
|
106
|
+
args: args[-1],
|
107
|
+
max_length: config_proxy.debug_last_hash_max_length
|
108
|
+
)
|
109
|
+
printed_args += ", #{printed}"
|
81
110
|
printed_args += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
82
111
|
end
|
83
112
|
else
|
84
|
-
|
85
|
-
|
86
|
-
|
113
|
+
printed, add_last_hash_ellipsis = debug_safe_proc(
|
114
|
+
proc_name:'last_hash_to_s_proc',
|
115
|
+
proc: config_proxy.debug_last_hash_to_s_proc,
|
116
|
+
args: args[0],
|
117
|
+
max_length: config_proxy.debug_last_hash_max_length
|
118
|
+
)
|
119
|
+
printed_args += printed
|
87
120
|
printed_args += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
88
121
|
end
|
89
122
|
else
|
90
|
-
printed_args += if
|
123
|
+
printed_args += if config_proxy.debug_args_to_s_proc
|
124
|
+
printed, add_args_ellipsis = debug_safe_proc(
|
125
|
+
proc_name:'args_to_s_proc',
|
126
|
+
proc: config_proxy.debug_args_to_s_proc,
|
127
|
+
args: args,
|
128
|
+
max_length: config_proxy.debug_args_max_length
|
129
|
+
)
|
130
|
+
printed
|
131
|
+
elsif args.length == 1 && args[0].is_a?(Hash)
|
91
132
|
# handle double splat
|
92
133
|
("**#{args.map(&:inspect).join(', ').tap do |x|
|
93
134
|
add_args_ellipsis = x.length > config_proxy.debug_args_max_length
|
@@ -102,6 +143,19 @@ module DebugLogging
|
|
102
143
|
"(#{printed_args})"
|
103
144
|
end
|
104
145
|
|
146
|
+
def debug_safe_proc(proc_name:, proc:, args:, max_length:)
|
147
|
+
max_length ||= 1000 # can't be nil
|
148
|
+
begin
|
149
|
+
add_ellipsis = false
|
150
|
+
printed = String(proc.call(args)).tap do |x|
|
151
|
+
add_ellipsis = x.length > max_length
|
152
|
+
end[0..(max_length)]
|
153
|
+
return printed, add_ellipsis
|
154
|
+
rescue => e
|
155
|
+
return "#{e.class}: #{e.message}\nPlease check that your #{proc_name} is able to handle #{args}", false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
105
159
|
def debug_payload_to_s(payload: nil, config_proxy: nil)
|
106
160
|
return '' unless payload && config_proxy
|
107
161
|
|
@@ -110,7 +164,16 @@ module DebugLogging
|
|
110
164
|
when true
|
111
165
|
payload.inspect
|
112
166
|
else
|
113
|
-
|
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
|
114
177
|
end
|
115
178
|
else
|
116
179
|
''
|
@@ -10,13 +10,15 @@ module DebugLogging
|
|
10
10
|
multiple_last_hashes: false,
|
11
11
|
last_hash_to_s_proc: nil,
|
12
12
|
last_hash_max_length: 1_000,
|
13
|
+
args_to_s_proc: nil,
|
13
14
|
args_max_length: 1_000,
|
14
15
|
colorized_chain_for_method: false,
|
15
16
|
colorized_chain_for_class: false,
|
16
17
|
add_invocation_id: true,
|
17
18
|
ellipsis: DEFAULT_ELLIPSIS,
|
18
19
|
mark_scope_exit: false,
|
19
|
-
add_payload: true
|
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
|
20
22
|
}.freeze
|
21
23
|
CONFIG_ATTRS = CONFIG_ATTRS_DEFAULTS.keys
|
22
24
|
CONFIG_READERS_DEFAULTS = {
|
@@ -42,6 +44,7 @@ module DebugLogging
|
|
42
44
|
# log_level: :debug # at what level do the messages created by this gem sent at?
|
43
45
|
# last_hash_to_s_proc: nil # e.g. ->(hash) { "keys: #{hash.keys}" }
|
44
46
|
# last_hash_max_length: 1_000
|
47
|
+
# args_to_s_proc: nil # e.g. ->(record) { "record id: #{record.id}" }
|
45
48
|
# args_max_length: 1_000
|
46
49
|
# instance_benchmarks: false
|
47
50
|
# class_benchmarks: false
|