debugtrace 0.2.7 → 0.3.1
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
- data/debugtrace.yml +3 -0
- data/lib/debugtrace/common.rb +1 -0
- data/lib/debugtrace/config.rb +1 -0
- data/lib/debugtrace/log_buffer.rb +3 -5
- data/lib/debugtrace/loggers.rb +1 -0
- data/lib/debugtrace/state.rb +1 -0
- data/lib/debugtrace/version.rb +2 -2
- data/lib/debugtrace.rb +97 -71
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67184688a8a3f8b4a4ff9de1ef04799cf6957d9e94907c86073c083e3b6c1b98
|
4
|
+
data.tar.gz: c410dcd81f2aa49f307b20200fe487a335871bbec830c15ba2a900a022d9a309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fea6b71189147084795ad686aaca7c9621382a3516167f40a1811a4a7b889f4bd3a2d44823ed8a252a156ec42dc29f6f88919cd229ca287ea893f77ea35dc44
|
7
|
+
data.tar.gz: 625c317abee13df3c3e67bf2a2250f2d3685f341e9a2370b936f6c853b325f46571c47851d79827e96de4a850c196d0d308a912f23eae4f15e25bab15d6d4470
|
data/debugtrace.yml
ADDED
data/lib/debugtrace/common.rb
CHANGED
data/lib/debugtrace/config.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# log_buffer.rb
|
2
3
|
# (C) 2025 Masato Kokubo
|
3
4
|
require_relative 'common'
|
@@ -85,17 +86,14 @@ class LogBuffer
|
|
85
86
|
|
86
87
|
# Appends lines of another LogBuffer.
|
87
88
|
#
|
88
|
-
# @param separator [String] the separator string to append if not ''
|
89
89
|
# @param buff [LogBuffer] another LogBuffer
|
90
90
|
# @return [LogBuffer] this object
|
91
|
-
def append_buffer(
|
92
|
-
Common.check_type('separator', separator, String)
|
91
|
+
def append_buffer(buff)
|
93
92
|
Common.check_type('buff', buff, LogBuffer)
|
94
|
-
append(separator, 0, true) if separator != ''
|
95
93
|
index = 0
|
96
94
|
for line in buff.lines
|
97
95
|
line_feed if index > 0
|
98
|
-
append(line.log, line.nest_level,
|
96
|
+
append(line.log, line.nest_level, true)
|
99
97
|
index += 1
|
100
98
|
end
|
101
99
|
return self
|
data/lib/debugtrace/loggers.rb
CHANGED
data/lib/debugtrace/state.rb
CHANGED
data/lib/debugtrace/version.rb
CHANGED
data/lib/debugtrace.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# debugtrace.rb
|
2
3
|
# (C) 2025 Masato Kokubo
|
3
4
|
require 'logger'
|
5
|
+
require 'set'
|
6
|
+
require 'date'
|
4
7
|
|
5
8
|
# Require necessary files
|
6
9
|
require_relative 'debugtrace/version'
|
@@ -12,6 +15,10 @@ require_relative 'debugtrace/state'
|
|
12
15
|
|
13
16
|
# The main module of DebugTrace-rb.
|
14
17
|
module DebugTrace
|
18
|
+
@@no_reflection_classes = [
|
19
|
+
FalseClass, TrueClass, Integer, Float, Rational, Complex, Range, Regexp,
|
20
|
+
]
|
21
|
+
|
15
22
|
# Configuration values
|
16
23
|
@@config = nil
|
17
24
|
|
@@ -136,54 +143,58 @@ module DebugTrace
|
|
136
143
|
def self.to_string(name, value, print_options)
|
137
144
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
138
145
|
|
139
|
-
separator = ''
|
140
146
|
unless name.empty?
|
141
|
-
buff.append(name)
|
142
|
-
separator = @@config.varname_value_separator
|
147
|
+
buff.append(name).no_break_append(@@config.varname_value_separator)
|
143
148
|
end
|
144
149
|
|
145
|
-
|
146
|
-
|
147
|
-
buff.no_break_append(separator).append('nil')
|
148
|
-
when FalseClass, TrueClass, Integer, Float
|
149
|
-
buff.no_break_append(separator).append(value.to_s)
|
150
|
-
when Symbol
|
151
|
-
buff.no_break_append(separator).append(':').no_break_append(value.name)
|
152
|
-
when Class
|
153
|
-
buff.no_break_append(separator).append(value.name).no_break_append(' class')
|
154
|
-
when Module
|
155
|
-
buff.no_break_append(separator).append(value.name).no_break_append(' module')
|
156
|
-
when String
|
157
|
-
value_buff = value.encoding == Encoding::ASCII_8BIT ?
|
158
|
-
to_string_bytes(value, print_options) : to_string_str(value, print_options)
|
159
|
-
buff.append_buffer(separator, value_buff)
|
160
|
-
when DateTime
|
161
|
-
buff.no_break_append(separator).append(value.strftime('%Y-%m-%d %H:%M-%S.%L%:z'))
|
162
|
-
when Date
|
163
|
-
buff.no_break_append(separator).append(value.strftime('%Y-%m-%d'))
|
164
|
-
when Time
|
165
|
-
buff.no_break_append(separator).append(value.strftime('%H:%M-%S.%L%:z'))
|
166
|
-
when Array, Set, Hash
|
167
|
-
value_buff = to_string_enumerable(value, print_options)
|
168
|
-
buff.append_buffer(separator, value_buff)
|
150
|
+
if @@no_reflection_classes.include?(value.class)
|
151
|
+
buff.append(value.to_s)
|
169
152
|
else
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
153
|
+
case value
|
154
|
+
when nil
|
155
|
+
buff.append('nil')
|
156
|
+
when Symbol
|
157
|
+
buff.append(':').no_break_append(value.name)
|
158
|
+
when Class
|
159
|
+
buff.append(value.name).no_break_append(' class')
|
160
|
+
when Module
|
161
|
+
buff.append(value.name).no_break_append(' module')
|
162
|
+
when String
|
163
|
+
value_buff = value.encoding == Encoding::ASCII_8BIT ?
|
164
|
+
to_string_bytes(value, print_options) : to_string_str(value, print_options)
|
165
|
+
buff.append_buffer(value_buff)
|
166
|
+
when DateTime, Time
|
167
|
+
buff.append(value.strftime('%Y-%m-%d %H:%M:%S.%L%:z'))
|
168
|
+
when Date
|
169
|
+
buff.append(value.strftime('%Y-%m-%d'))
|
170
|
+
when Dir, File
|
171
|
+
buff.append(value.class.name)
|
172
|
+
buff.append_buffer(to_string_str(value.path, print_options))
|
173
|
+
when Array, Set, Hash
|
174
|
+
value_buff = to_string_enumerable(value, print_options)
|
175
|
+
buff.append_buffer(value_buff)
|
176
|
+
else
|
177
|
+
reflection = print_options.reflection || value.class.superclass == Struct
|
178
|
+
|
179
|
+
to_s_string = reflection ? '' : value.to_s
|
180
|
+
if reflection || to_s_string.start_with?('#<')
|
181
|
+
# use reflection
|
182
|
+
value_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
183
|
+
if @@reflected_objects.any? { |obj| value.equal?(obj) }
|
184
|
+
# cyclic reference
|
185
|
+
value_buff.no_break_append(@@config.cyclic_reference_string)
|
186
|
+
elsif @@reflected_objects.length > print_options.reflection_limit
|
187
|
+
# over reflection level limitation
|
188
|
+
value_buff.no_break_append(@@config.limit_string)
|
189
|
+
else
|
190
|
+
@@reflected_objects.push(value)
|
191
|
+
value_buff = to_string_reflection(value, print_options)
|
192
|
+
@@reflected_objects.pop
|
193
|
+
end
|
194
|
+
buff.append_buffer(value_buff)
|
179
195
|
else
|
180
|
-
|
181
|
-
value_buff = to_string_reflection(value, print_options)
|
182
|
-
@@reflected_objects.pop
|
196
|
+
buff.append(to_s_string)
|
183
197
|
end
|
184
|
-
buff.append_buffer(separator, value_buff)
|
185
|
-
else
|
186
|
-
buff.no_break_append(separator).append(value.to_s)
|
187
198
|
end
|
188
199
|
end
|
189
200
|
|
@@ -195,12 +206,11 @@ module DebugTrace
|
|
195
206
|
# @param value [String] the value
|
196
207
|
# @param print_options [PrintOptions] the print options
|
197
208
|
def self.to_string_str(value, print_options)
|
198
|
-
|
199
|
-
has_double_quote = false
|
209
|
+
double_quote = false
|
200
210
|
single_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
201
211
|
double_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
202
212
|
|
203
|
-
if value.length >=
|
213
|
+
if value.length >= print_options.minimum_output_length
|
204
214
|
single_quote_buff.no_break_append(format(@@config.length_format, value.length))
|
205
215
|
double_quote_buff.no_break_append(format(@@config.length_format, value.length))
|
206
216
|
end
|
@@ -217,30 +227,28 @@ module DebugTrace
|
|
217
227
|
end
|
218
228
|
case char
|
219
229
|
when "'"
|
220
|
-
|
230
|
+
double_quote = true
|
221
231
|
double_quote_buff.no_break_append(char)
|
222
|
-
has_single_quote = true
|
223
232
|
when '"'
|
224
233
|
single_quote_buff.no_break_append(char)
|
225
234
|
double_quote_buff.no_break_append("\\\"")
|
226
|
-
has_double_quote = true
|
227
235
|
when "\\"
|
228
|
-
|
236
|
+
double_quote = true
|
229
237
|
double_quote_buff.no_break_append("\\\\")
|
230
238
|
when "\n"
|
231
|
-
|
239
|
+
double_quote = true
|
232
240
|
double_quote_buff.no_break_append("\\n")
|
233
241
|
when "\r"
|
234
|
-
|
242
|
+
double_quote = true
|
235
243
|
double_quote_buff.no_break_append("\\r")
|
236
244
|
when "\t"
|
237
|
-
|
245
|
+
double_quote = true
|
238
246
|
double_quote_buff.no_break_append("\\t")
|
239
247
|
else
|
240
248
|
char_ord = char.ord
|
241
249
|
if char_ord >= 0x00 && char_ord <= 0x1F || char_ord == 0x7F
|
250
|
+
double_quote = true
|
242
251
|
num_str = format('%02X', char_ord)
|
243
|
-
single_quote_buff.no_break_append("\\x" + num_str)
|
244
252
|
double_quote_buff.no_break_append("\\x" + num_str)
|
245
253
|
else
|
246
254
|
single_quote_buff.no_break_append(char)
|
@@ -253,7 +261,7 @@ module DebugTrace
|
|
253
261
|
double_quote_buff.no_break_append('"')
|
254
262
|
single_quote_buff.no_break_append("'")
|
255
263
|
|
256
|
-
return
|
264
|
+
return double_quote ? double_quote_buff : single_quote_buff
|
257
265
|
end
|
258
266
|
|
259
267
|
# Returns a string representation of the string value which encoding is ASCII_8BIT.
|
@@ -264,8 +272,8 @@ module DebugTrace
|
|
264
272
|
bytes_length = value.length
|
265
273
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
266
274
|
|
267
|
-
if bytes_length >=
|
268
|
-
buff.no_break_append(format(@@config.
|
275
|
+
if bytes_length >= print_options.minimum_output_length
|
276
|
+
buff.no_break_append(format(@@config.length_format, bytes_length))
|
269
277
|
end
|
270
278
|
|
271
279
|
buff.no_break_append('[')
|
@@ -321,7 +329,7 @@ module DebugTrace
|
|
321
329
|
def self.to_string_reflection(value, print_options)
|
322
330
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
323
331
|
|
324
|
-
buff.append(get_type_name(value))
|
332
|
+
buff.append(get_type_name(value, -1, print_options))
|
325
333
|
|
326
334
|
body_buff = to_string_reflection_body(value, print_options)
|
327
335
|
|
@@ -333,7 +341,7 @@ module DebugTrace
|
|
333
341
|
buff.up_nest
|
334
342
|
end
|
335
343
|
|
336
|
-
buff.append_buffer(
|
344
|
+
buff.append_buffer(body_buff)
|
337
345
|
|
338
346
|
if multi_lines
|
339
347
|
buff.line_feed if buff.length > 0
|
@@ -350,25 +358,42 @@ module DebugTrace
|
|
350
358
|
# @param print_options [PrintOptions] the print options
|
351
359
|
def self.to_string_reflection_body(value, print_options)
|
352
360
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
353
|
-
|
354
|
-
variables = value.instance_variables
|
355
|
-
|
356
361
|
multi_lines = false
|
357
362
|
index = 0
|
363
|
+
|
364
|
+
variables = value.instance_variables
|
358
365
|
variables.each do |variable|
|
359
366
|
buff.no_break_append(', ') if index > 0
|
360
367
|
|
361
368
|
var_value = value.instance_variable_get(variable)
|
362
369
|
member_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
363
|
-
member_buff.append(variable)
|
364
|
-
member_buff.append_buffer(
|
370
|
+
member_buff.append(variable).no_break_append(@@config.key_value_separator)
|
371
|
+
member_buff.append_buffer(to_string('', var_value, print_options))
|
365
372
|
buff.line_feed if index > 0 && (multi_lines || member_buff.multi_lines?)
|
366
|
-
buff.append_buffer(
|
373
|
+
buff.append_buffer(member_buff)
|
367
374
|
|
368
375
|
multi_lines = member_buff.multi_lines?
|
369
376
|
index += 1
|
370
377
|
end
|
371
378
|
|
379
|
+
if value.class.superclass == Struct
|
380
|
+
members = value.members
|
381
|
+
hash = value.to_h
|
382
|
+
members.each do |member|
|
383
|
+
buff.no_break_append(', ') if index > 0
|
384
|
+
|
385
|
+
var_value = hash[member]
|
386
|
+
member_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
387
|
+
member_buff.append(member).no_break_append(@@config.key_value_separator)
|
388
|
+
member_buff.append_buffer(to_string('', var_value, print_options))
|
389
|
+
buff.line_feed if index > 0 && (multi_lines || member_buff.multi_lines?)
|
390
|
+
buff.append_buffer(member_buff)
|
391
|
+
|
392
|
+
multi_lines = member_buff.multi_lines?
|
393
|
+
index += 1
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
372
397
|
return buff
|
373
398
|
end
|
374
399
|
|
@@ -391,7 +416,7 @@ module DebugTrace
|
|
391
416
|
end
|
392
417
|
|
393
418
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
394
|
-
buff.append(get_type_name(values, values.
|
419
|
+
buff.append(get_type_name(values, values.size, print_options))
|
395
420
|
buff.no_break_append(open_char)
|
396
421
|
|
397
422
|
body_buff = to_string_enumerable_body(values, print_options)
|
@@ -403,7 +428,7 @@ module DebugTrace
|
|
403
428
|
buff.up_nest
|
404
429
|
end
|
405
430
|
|
406
|
-
buff.append_buffer(
|
431
|
+
buff.append_buffer(body_buff)
|
407
432
|
|
408
433
|
if multi_lines
|
409
434
|
buff.line_feed
|
@@ -442,7 +467,7 @@ module DebugTrace
|
|
442
467
|
end
|
443
468
|
|
444
469
|
buff.line_feed if index > 0 && (multi_lines || element_buff.multi_lines?)
|
445
|
-
buff.append_buffer(
|
470
|
+
buff.append_buffer(element_buff)
|
446
471
|
|
447
472
|
multi_lines = element_buff.multi_lines?
|
448
473
|
index += 1
|
@@ -462,19 +487,20 @@ module DebugTrace
|
|
462
487
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
463
488
|
key_buff = to_string('', key, print_options)
|
464
489
|
value_buff = to_string('', value, print_options)
|
465
|
-
buff.append_buffer(
|
490
|
+
buff.append_buffer(key_buff).no_break_append(@@config.key_value_separator).append_buffer(value_buff)
|
466
491
|
buff
|
467
492
|
end
|
468
493
|
|
469
494
|
# Returns the type name.
|
470
495
|
#
|
471
496
|
# @param value [Object] the value
|
472
|
-
# @
|
473
|
-
|
497
|
+
# @param size [Object] the size of Array, Set or Hash
|
498
|
+
# @param print_options [PrintOptions] the print options
|
499
|
+
def self.get_type_name(value, size, print_options)
|
474
500
|
type_name = value.class.to_s
|
475
501
|
type_name = '' if %w[Array Hash Set].include?(type_name)
|
476
502
|
|
477
|
-
if size >=
|
503
|
+
if size >= print_options.minimum_output_size
|
478
504
|
type_name += @@config.size_format % size
|
479
505
|
end
|
480
506
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debugtrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masato Kokubo
|
@@ -23,6 +23,7 @@ files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
|
+
- debugtrace.yml
|
26
27
|
- lib/debugtrace.rb
|
27
28
|
- lib/debugtrace/common.rb
|
28
29
|
- lib/debugtrace/config.rb
|