debugtrace 0.3.0 → 1.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
- data/README.md +568 -16
- data/README_ja.md +590 -0
- data/examples/debugtrace.yml +28 -0
- data/examples/readme-example.rb +36 -0
- data/lib/debugtrace/config.rb +31 -33
- data/lib/debugtrace/log_buffer.rb +5 -8
- data/lib/debugtrace/loggers.rb +7 -7
- data/lib/debugtrace/version.rb +1 -1
- data/lib/debugtrace.rb +118 -88
- metadata +6 -4
- data/debugtrace.yml +0 -2
- /data/{LICENSE → LICENSE.txt} +0 -0
data/lib/debugtrace/config.rb
CHANGED
@@ -10,8 +10,8 @@ class Config
|
|
10
10
|
attr_reader :config
|
11
11
|
attr_reader :logger_name
|
12
12
|
attr_reader :log_path
|
13
|
-
attr_reader :
|
14
|
-
attr_reader :
|
13
|
+
attr_reader :rubylogger_format
|
14
|
+
attr_reader :log_datetime_format
|
15
15
|
attr_reader :enter_format
|
16
16
|
attr_reader :leave_format
|
17
17
|
attr_reader :thread_boundary_format
|
@@ -19,8 +19,7 @@ class Config
|
|
19
19
|
attr_reader :indent_string
|
20
20
|
attr_reader :data_indent_string
|
21
21
|
attr_reader :limit_string
|
22
|
-
attr_reader :
|
23
|
-
attr_reader :cyclic_reference_string
|
22
|
+
attr_reader :circular_reference_string
|
24
23
|
attr_reader :varname_value_separator
|
25
24
|
attr_reader :key_value_separator
|
26
25
|
attr_reader :print_suffix_format
|
@@ -28,11 +27,11 @@ class Config
|
|
28
27
|
attr_reader :minimum_output_size
|
29
28
|
attr_reader :length_format
|
30
29
|
attr_reader :minimum_output_length
|
31
|
-
attr_reader :
|
30
|
+
attr_reader :data_output_width
|
32
31
|
attr_reader :bytes_count_in_line
|
33
32
|
attr_reader :collection_limit
|
34
|
-
attr_reader :bytes_limit
|
35
33
|
attr_reader :string_limit
|
34
|
+
attr_reader :bytes_limit
|
36
35
|
attr_reader :reflection_limit
|
37
36
|
|
38
37
|
# Initializes with a yml file in the config_path.
|
@@ -46,33 +45,32 @@ class Config
|
|
46
45
|
@config_path = '<No config file>'
|
47
46
|
@config = nil
|
48
47
|
end
|
49
|
-
@logger_name = get_value 'logger'
|
50
|
-
@log_path = get_value 'log_path'
|
51
|
-
@
|
52
|
-
@
|
53
|
-
@enabled = get_value 'enabled'
|
54
|
-
@enter_format = get_value 'enter_format'
|
55
|
-
@leave_format = get_value 'leave_format'
|
56
|
-
@thread_boundary_format = get_value 'thread_boundary_format'
|
57
|
-
@maximum_indents = get_value 'maximum_indents'
|
58
|
-
@indent_string = get_value 'indent_string'
|
59
|
-
@data_indent_string = get_value 'data_indent_string'
|
60
|
-
@limit_string = get_value 'limit_string'
|
61
|
-
@
|
62
|
-
@
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
66
|
-
@
|
67
|
-
@
|
68
|
-
@
|
69
|
-
@
|
70
|
-
@
|
71
|
-
@
|
72
|
-
@
|
73
|
-
@bytes_limit = get_value 'bytes_limit'
|
74
|
-
@
|
75
|
-
@reflection_limit = get_value 'reflection_limit' , 4
|
48
|
+
@logger_name = get_value 'logger' , 'stderr'
|
49
|
+
@log_path = get_value 'log_path' , 'debugtrace.log'
|
50
|
+
@rubylogger_format = get_value 'rubylogger_format' , "%2$s %1$s %4$s\n"
|
51
|
+
@log_datetime_format = get_value 'log_datetime_format' , '%Y-%m-%d %H:%M:%S.%L%:z'
|
52
|
+
@enabled = get_value 'enabled' , true
|
53
|
+
@enter_format = get_value 'enter_format' , 'Enter %1$s (%2$s:%3$d) <- %4$s (%5$s:%6$d)'
|
54
|
+
@leave_format = get_value 'leave_format' , 'Leave %1$s (%2$s:%3$d) duration: %4$.3f ms'
|
55
|
+
@thread_boundary_format = get_value 'thread_boundary_format' , '______________________________ %1$s #%2$d ______________________________'
|
56
|
+
@maximum_indents = get_value 'maximum_indents' , 32
|
57
|
+
@indent_string = get_value 'indent_string' , '| '
|
58
|
+
@data_indent_string = get_value 'data_indent_string' , ' '
|
59
|
+
@limit_string = get_value 'limit_string' , '...'
|
60
|
+
@circular_reference_string = get_value 'circular_reference_string' , '*** Circular Reference ***'
|
61
|
+
@varname_value_separator = get_value 'varname_value_separator' , ' = '
|
62
|
+
@key_value_separator = get_value 'key_value_separator' , ': '
|
63
|
+
@print_suffix_format = get_value 'print_suffix_format' , ' (%2$s:%3$d)'
|
64
|
+
@size_format = get_value 'size_format' , '(size:%d)'
|
65
|
+
@minimum_output_size = get_value 'minimum_output_size' , 256
|
66
|
+
@length_format = get_value 'length_format' , '(length:%d)'
|
67
|
+
@minimum_output_length = get_value 'minimum_output_length' , 256
|
68
|
+
@data_output_width = get_value 'data_output_width' , 70
|
69
|
+
@bytes_count_in_line = get_value 'bytes_count_in_line' , 16
|
70
|
+
@collection_limit = get_value 'collection_limit' , 128
|
71
|
+
@string_limit = get_value 'string_limit' , 256
|
72
|
+
@bytes_limit = get_value 'bytes_limit' , 256
|
73
|
+
@reflection_limit = get_value 'reflection_limit' , 4
|
76
74
|
end
|
77
75
|
|
78
76
|
# Returns true if logging is enabled, false otherwise.
|
@@ -27,8 +27,8 @@ class LogBuffer
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# Initializes this object.
|
30
|
-
def initialize(
|
31
|
-
@
|
30
|
+
def initialize(data_output_width)
|
31
|
+
@data_output_width = Common.check_type('data_output_width', data_output_width, Integer)
|
32
32
|
@nest_level = 0
|
33
33
|
@append_nest_level = 0
|
34
34
|
|
@@ -68,7 +68,7 @@ class LogBuffer
|
|
68
68
|
Common.check_type('no_break', no_break, TrueClass)
|
69
69
|
unless value.nil?
|
70
70
|
string = value.to_s
|
71
|
-
line_feed if !no_break && length > 0 && length + string.length > @
|
71
|
+
line_feed if !no_break && length > 0 && length + string.length > @data_output_width
|
72
72
|
@append_nest_level = nest_level
|
73
73
|
@last_line += string
|
74
74
|
end
|
@@ -86,17 +86,14 @@ class LogBuffer
|
|
86
86
|
|
87
87
|
# Appends lines of another LogBuffer.
|
88
88
|
#
|
89
|
-
# @param separator [String] the separator string to append if not ''
|
90
89
|
# @param buff [LogBuffer] another LogBuffer
|
91
90
|
# @return [LogBuffer] this object
|
92
|
-
def append_buffer(
|
93
|
-
Common.check_type('separator', separator, String)
|
91
|
+
def append_buffer(buff)
|
94
92
|
Common.check_type('buff', buff, LogBuffer)
|
95
|
-
append(separator, 0, true) if separator != ''
|
96
93
|
index = 0
|
97
94
|
for line in buff.lines
|
98
95
|
line_feed if index > 0
|
99
|
-
append(line.log, line.nest_level,
|
96
|
+
append(line.log, line.nest_level, true)
|
100
97
|
index += 1
|
101
98
|
end
|
102
99
|
return self
|
data/lib/debugtrace/loggers.rb
CHANGED
@@ -35,7 +35,7 @@ class StdLogger < LoggerBase
|
|
35
35
|
# @return [String] the message
|
36
36
|
def print(message)
|
37
37
|
Common::check_type("message", message, String)
|
38
|
-
datetime_str = Time.now().strftime(@config.
|
38
|
+
datetime_str = Time.now().strftime(@config.log_datetime_format)
|
39
39
|
@output.puts "#{datetime_str} #{message}"
|
40
40
|
end
|
41
41
|
|
@@ -60,7 +60,7 @@ class StdErrLogger < StdLogger
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# A logger class that outputs using Ruby Logger.
|
63
|
-
class RubyLogger
|
63
|
+
class RubyLogger < LoggerBase
|
64
64
|
private
|
65
65
|
|
66
66
|
class Formatter
|
@@ -71,8 +71,8 @@ class RubyLogger
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def call(severity, datetime, progname, msg)
|
74
|
-
datetime_str = datetime.strftime(@config.
|
75
|
-
format(@config.
|
74
|
+
datetime_str = datetime.strftime(@config.log_datetime_format)
|
75
|
+
format(@config.rubylogger_format, severity, datetime_str, progname, msg)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -86,7 +86,7 @@ class RubyLogger
|
|
86
86
|
@logger = Logger.new(
|
87
87
|
@config.log_path,
|
88
88
|
formatter: Formatter.new(@config),
|
89
|
-
datetime_format: @config.
|
89
|
+
datetime_format: @config.log_datetime_format)
|
90
90
|
end
|
91
91
|
|
92
92
|
# Outputs the message.
|
@@ -94,7 +94,7 @@ class RubyLogger
|
|
94
94
|
# @param message [String] The message to output
|
95
95
|
def print(message)
|
96
96
|
Common::check_type("message", message, String)
|
97
|
-
@logger.log(Logger::Severity::DEBUG, message, 'DebugTrace
|
97
|
+
@logger.log(Logger::Severity::DEBUG, message, 'DebugTrace')
|
98
98
|
return message
|
99
99
|
end
|
100
100
|
|
@@ -146,7 +146,7 @@ class FileLogger < LoggerBase
|
|
146
146
|
def print(message)
|
147
147
|
if File.exist?(@log_path)
|
148
148
|
File.open(@log_path, 'a') { |file|
|
149
|
-
datetime_str = Time.now().strftime(@config.
|
149
|
+
datetime_str = Time.now().strftime(@config.log_datetime_format)
|
150
150
|
file.puts "#{datetime_str} #{message}"
|
151
151
|
}
|
152
152
|
end
|
data/lib/debugtrace/version.rb
CHANGED
data/lib/debugtrace.rb
CHANGED
@@ -15,6 +15,10 @@ require_relative 'debugtrace/state'
|
|
15
15
|
|
16
16
|
# The main module of DebugTrace-rb.
|
17
17
|
module DebugTrace
|
18
|
+
@@no_reflection_classes = [
|
19
|
+
FalseClass, TrueClass, Integer, Float, Rational, Complex, Range, Regexp,
|
20
|
+
]
|
21
|
+
|
18
22
|
# Configuration values
|
19
23
|
@@config = nil
|
20
24
|
|
@@ -40,13 +44,21 @@ module DebugTrace
|
|
40
44
|
# The logger used by DebugTrace-py
|
41
45
|
@@logger = nil
|
42
46
|
|
47
|
+
# The before thread id
|
48
|
+
@@before_thread_id = nil
|
49
|
+
|
50
|
+
@@DO_NOT_OUTPUT = 'Do not output'
|
51
|
+
|
43
52
|
# Initialize this class
|
44
|
-
|
45
|
-
|
46
|
-
|
53
|
+
def self.initialize()
|
54
|
+
config_path = ENV['DEBUGTRACE_CONFIG']
|
55
|
+
if config_path == ''
|
56
|
+
config_path = './debugtrace.yml'
|
57
|
+
end
|
58
|
+
|
47
59
|
@@config = Config.new(config_path)
|
48
60
|
|
49
|
-
@@last_log_buff = LogBuffer.new(@@config.
|
61
|
+
@@last_log_buff = LogBuffer.new(@@config.data_output_width)
|
50
62
|
|
51
63
|
# Decide the logger class
|
52
64
|
case @@config.logger_name.downcase
|
@@ -65,7 +77,7 @@ module DebugTrace
|
|
65
77
|
|
66
78
|
return unless @@config.enabled?
|
67
79
|
|
68
|
-
config_path = File.expand_path(@@config.config_path)
|
80
|
+
config_path = @@config.config == nil ? @@config.config_path : File.expand_path(@@config.config_path)
|
69
81
|
@@logger.print("DebugTrace-rb #{DebugTrace::VERSION} on Ruby #{RUBY_VERSION}")
|
70
82
|
@@logger.print(" config file: #{config_path}")
|
71
83
|
@@logger.print(" logger: #{@@logger}")
|
@@ -137,56 +149,60 @@ module DebugTrace
|
|
137
149
|
# @param value [Object] the value
|
138
150
|
# @param print_options [PrintOptions] the print options
|
139
151
|
def self.to_string(name, value, print_options)
|
140
|
-
buff = LogBuffer.new(@@config.
|
152
|
+
buff = LogBuffer.new(@@config.data_output_width)
|
141
153
|
|
142
|
-
separator = ''
|
143
154
|
unless name.empty?
|
144
|
-
buff.append(name)
|
145
|
-
separator = @@config.varname_value_separator
|
155
|
+
buff.append(name).no_break_append(@@config.varname_value_separator)
|
146
156
|
end
|
147
157
|
|
148
|
-
|
149
|
-
|
150
|
-
buff.no_break_append(separator).append('nil')
|
151
|
-
when FalseClass, TrueClass, Integer, Float
|
152
|
-
buff.no_break_append(separator).append(value.to_s)
|
153
|
-
when Symbol
|
154
|
-
buff.no_break_append(separator).append(':').no_break_append(value.name)
|
155
|
-
when Class
|
156
|
-
buff.no_break_append(separator).append(value.name).no_break_append(' class')
|
157
|
-
when Module
|
158
|
-
buff.no_break_append(separator).append(value.name).no_break_append(' module')
|
159
|
-
when String
|
160
|
-
value_buff = value.encoding == Encoding::ASCII_8BIT ?
|
161
|
-
to_string_bytes(value, print_options) : to_string_str(value, print_options)
|
162
|
-
buff.append_buffer(separator, value_buff)
|
163
|
-
when DateTime
|
164
|
-
buff.no_break_append(separator).append(value.strftime('%Y-%m-%d %H:%M-%S.%L%:z'))
|
165
|
-
when Date
|
166
|
-
buff.no_break_append(separator).append(value.strftime('%Y-%m-%d'))
|
167
|
-
when Time
|
168
|
-
buff.no_break_append(separator).append(value.strftime('%H:%M-%S.%L%:z'))
|
169
|
-
when Array, Set, Hash
|
170
|
-
value_buff = to_string_enumerable(value, print_options)
|
171
|
-
buff.append_buffer(separator, value_buff)
|
158
|
+
if @@no_reflection_classes.include?(value.class)
|
159
|
+
buff.append(value.to_s)
|
172
160
|
else
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
161
|
+
case value
|
162
|
+
when nil
|
163
|
+
buff.append('nil')
|
164
|
+
when Symbol
|
165
|
+
buff.append(':').no_break_append(value.name)
|
166
|
+
when Class
|
167
|
+
buff.append(value.name).no_break_append(' class')
|
168
|
+
when Module
|
169
|
+
buff.append(value.name).no_break_append(' module')
|
170
|
+
when String
|
171
|
+
value_buff = value.encoding == Encoding::ASCII_8BIT ?
|
172
|
+
to_string_bytes(value, print_options) : to_string_str(value, print_options)
|
173
|
+
buff.append_buffer(value_buff)
|
174
|
+
when DateTime, Time
|
175
|
+
buff.append(value.strftime('%Y-%m-%d %H:%M:%S.%L%:z'))
|
176
|
+
when Date
|
177
|
+
buff.append(value.strftime('%Y-%m-%d'))
|
178
|
+
when Dir, File
|
179
|
+
buff.append(value.class.name)
|
180
|
+
buff.append_buffer(to_string_str(value.path, print_options))
|
181
|
+
when Array, Set, Hash
|
182
|
+
value_buff = to_string_enumerable(value, print_options)
|
183
|
+
buff.append_buffer(value_buff)
|
184
|
+
else
|
185
|
+
reflection = print_options.reflection || value.class.superclass == Struct
|
186
|
+
|
187
|
+
to_s_string = reflection ? '' : value.to_s
|
188
|
+
if reflection || to_s_string.start_with?('#<')
|
189
|
+
# use reflection
|
190
|
+
value_buff = LogBuffer.new(@@config.data_output_width)
|
191
|
+
if @@reflected_objects.any? { |obj| value.equal?(obj) }
|
192
|
+
# cyclic reference
|
193
|
+
value_buff.no_break_append(@@config.circular_reference_string)
|
194
|
+
elsif @@reflected_objects.length > print_options.reflection_limit
|
195
|
+
# over reflection level limitation
|
196
|
+
value_buff.no_break_append(@@config.limit_string)
|
197
|
+
else
|
198
|
+
@@reflected_objects.push(value)
|
199
|
+
value_buff = to_string_reflection(value, print_options)
|
200
|
+
@@reflected_objects.pop
|
201
|
+
end
|
202
|
+
buff.append_buffer(value_buff)
|
182
203
|
else
|
183
|
-
|
184
|
-
value_buff = to_string_reflection(value, print_options)
|
185
|
-
@@reflected_objects.pop
|
204
|
+
buff.append(to_s_string)
|
186
205
|
end
|
187
|
-
buff.append_buffer(separator, value_buff)
|
188
|
-
else
|
189
|
-
buff.no_break_append(separator).append(value.to_s)
|
190
206
|
end
|
191
207
|
end
|
192
208
|
|
@@ -199,10 +215,10 @@ module DebugTrace
|
|
199
215
|
# @param print_options [PrintOptions] the print options
|
200
216
|
def self.to_string_str(value, print_options)
|
201
217
|
double_quote = false
|
202
|
-
single_quote_buff = LogBuffer.new(@@config.
|
203
|
-
double_quote_buff = LogBuffer.new(@@config.
|
218
|
+
single_quote_buff = LogBuffer.new(@@config.data_output_width)
|
219
|
+
double_quote_buff = LogBuffer.new(@@config.data_output_width)
|
204
220
|
|
205
|
-
if value.length >=
|
221
|
+
if value.length >= print_options.minimum_output_length
|
206
222
|
single_quote_buff.no_break_append(format(@@config.length_format, value.length))
|
207
223
|
double_quote_buff.no_break_append(format(@@config.length_format, value.length))
|
208
224
|
end
|
@@ -262,10 +278,10 @@ module DebugTrace
|
|
262
278
|
# @param print_options [PrintOptions] the print options
|
263
279
|
def self.to_string_bytes(value, print_options)
|
264
280
|
bytes_length = value.length
|
265
|
-
buff = LogBuffer.new(@@config.
|
281
|
+
buff = LogBuffer.new(@@config.data_output_width)
|
266
282
|
|
267
|
-
if bytes_length >=
|
268
|
-
buff.no_break_append(format(@@config.
|
283
|
+
if bytes_length >= print_options.minimum_output_length
|
284
|
+
buff.no_break_append(format(@@config.length_format, bytes_length))
|
269
285
|
end
|
270
286
|
|
271
287
|
buff.no_break_append('[')
|
@@ -319,13 +335,13 @@ module DebugTrace
|
|
319
335
|
# @param value [Object] the value
|
320
336
|
# @param print_options [PrintOptions] the print options
|
321
337
|
def self.to_string_reflection(value, print_options)
|
322
|
-
buff = LogBuffer.new(@@config.
|
338
|
+
buff = LogBuffer.new(@@config.data_output_width)
|
323
339
|
|
324
|
-
buff.append(get_type_name(value))
|
340
|
+
buff.append(get_type_name(value, -1, print_options))
|
325
341
|
|
326
342
|
body_buff = to_string_reflection_body(value, print_options)
|
327
343
|
|
328
|
-
multi_lines = body_buff.multi_lines? || buff.length + body_buff.length > @@config.
|
344
|
+
multi_lines = body_buff.multi_lines? || buff.length + body_buff.length > @@config.data_output_width
|
329
345
|
|
330
346
|
buff.no_break_append('{')
|
331
347
|
if multi_lines
|
@@ -333,7 +349,7 @@ module DebugTrace
|
|
333
349
|
buff.up_nest
|
334
350
|
end
|
335
351
|
|
336
|
-
buff.append_buffer(
|
352
|
+
buff.append_buffer(body_buff)
|
337
353
|
|
338
354
|
if multi_lines
|
339
355
|
buff.line_feed if buff.length > 0
|
@@ -349,26 +365,43 @@ module DebugTrace
|
|
349
365
|
# @param value [Object] the value
|
350
366
|
# @param print_options [PrintOptions] the print options
|
351
367
|
def self.to_string_reflection_body(value, print_options)
|
352
|
-
buff = LogBuffer.new(@@config.
|
353
|
-
|
354
|
-
variables = value.instance_variables
|
355
|
-
|
368
|
+
buff = LogBuffer.new(@@config.data_output_width)
|
356
369
|
multi_lines = false
|
357
370
|
index = 0
|
371
|
+
|
372
|
+
variables = value.instance_variables
|
358
373
|
variables.each do |variable|
|
359
374
|
buff.no_break_append(', ') if index > 0
|
360
375
|
|
361
376
|
var_value = value.instance_variable_get(variable)
|
362
|
-
member_buff = LogBuffer.new(@@config.
|
363
|
-
member_buff.append(variable)
|
364
|
-
member_buff.append_buffer(
|
377
|
+
member_buff = LogBuffer.new(@@config.data_output_width)
|
378
|
+
member_buff.append(variable).no_break_append(@@config.key_value_separator)
|
379
|
+
member_buff.append_buffer(to_string('', var_value, print_options))
|
365
380
|
buff.line_feed if index > 0 && (multi_lines || member_buff.multi_lines?)
|
366
|
-
buff.append_buffer(
|
381
|
+
buff.append_buffer(member_buff)
|
367
382
|
|
368
383
|
multi_lines = member_buff.multi_lines?
|
369
384
|
index += 1
|
370
385
|
end
|
371
386
|
|
387
|
+
if value.class.superclass == Struct
|
388
|
+
members = value.members
|
389
|
+
hash = value.to_h
|
390
|
+
members.each do |member|
|
391
|
+
buff.no_break_append(', ') if index > 0
|
392
|
+
|
393
|
+
var_value = hash[member]
|
394
|
+
member_buff = LogBuffer.new(@@config.data_output_width)
|
395
|
+
member_buff.append(member).no_break_append(@@config.key_value_separator)
|
396
|
+
member_buff.append_buffer(to_string('', var_value, print_options))
|
397
|
+
buff.line_feed if index > 0 && (multi_lines || member_buff.multi_lines?)
|
398
|
+
buff.append_buffer(member_buff)
|
399
|
+
|
400
|
+
multi_lines = member_buff.multi_lines?
|
401
|
+
index += 1
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
372
405
|
return buff
|
373
406
|
end
|
374
407
|
|
@@ -390,20 +423,20 @@ module DebugTrace
|
|
390
423
|
close_char = ']'
|
391
424
|
end
|
392
425
|
|
393
|
-
buff = LogBuffer.new(@@config.
|
394
|
-
buff.append(get_type_name(values, values.
|
426
|
+
buff = LogBuffer.new(@@config.data_output_width)
|
427
|
+
buff.append(get_type_name(values, values.size, print_options))
|
395
428
|
buff.no_break_append(open_char)
|
396
429
|
|
397
430
|
body_buff = to_string_enumerable_body(values, print_options)
|
398
431
|
|
399
|
-
multi_lines = body_buff.multi_lines? || buff.length + body_buff.length > @@config.
|
432
|
+
multi_lines = body_buff.multi_lines? || buff.length + body_buff.length > @@config.data_output_width
|
400
433
|
|
401
434
|
if multi_lines
|
402
435
|
buff.line_feed
|
403
436
|
buff.up_nest
|
404
437
|
end
|
405
438
|
|
406
|
-
buff.append_buffer(
|
439
|
+
buff.append_buffer(body_buff)
|
407
440
|
|
408
441
|
if multi_lines
|
409
442
|
buff.line_feed
|
@@ -420,7 +453,7 @@ module DebugTrace
|
|
420
453
|
# @param value [Array, Set, Hash] the value
|
421
454
|
# @param print_options [PrintOptions] the print options
|
422
455
|
def self.to_string_enumerable_body(values, print_options)
|
423
|
-
buff = LogBuffer.new(@@config.
|
456
|
+
buff = LogBuffer.new(@@config.data_output_width)
|
424
457
|
|
425
458
|
multi_lines = false
|
426
459
|
index = 0
|
@@ -442,7 +475,7 @@ module DebugTrace
|
|
442
475
|
end
|
443
476
|
|
444
477
|
buff.line_feed if index > 0 && (multi_lines || element_buff.multi_lines?)
|
445
|
-
buff.append_buffer(
|
478
|
+
buff.append_buffer(element_buff)
|
446
479
|
|
447
480
|
multi_lines = element_buff.multi_lines?
|
448
481
|
index += 1
|
@@ -459,36 +492,35 @@ module DebugTrace
|
|
459
492
|
# @param value [Object] the value
|
460
493
|
# @param print_options [PrintOptions] the print options
|
461
494
|
def self.to_string_key_value(key, value, print_options)
|
462
|
-
buff = LogBuffer.new(@@config.
|
495
|
+
buff = LogBuffer.new(@@config.data_output_width)
|
463
496
|
key_buff = to_string('', key, print_options)
|
464
497
|
value_buff = to_string('', value, print_options)
|
465
|
-
buff.append_buffer(
|
498
|
+
buff.append_buffer(key_buff).no_break_append(@@config.key_value_separator).append_buffer(value_buff)
|
466
499
|
buff
|
467
500
|
end
|
468
501
|
|
469
502
|
# Returns the type name.
|
470
503
|
#
|
471
504
|
# @param value [Object] the value
|
472
|
-
# @
|
473
|
-
|
505
|
+
# @param size [Object] the size of Array, Set or Hash
|
506
|
+
# @param print_options [PrintOptions] the print options
|
507
|
+
def self.get_type_name(value, size, print_options)
|
474
508
|
type_name = value.class.to_s
|
475
509
|
type_name = '' if %w[Array Hash Set].include?(type_name)
|
476
510
|
|
477
|
-
if size >=
|
511
|
+
if size >= print_options.minimum_output_size
|
478
512
|
type_name += @@config.size_format % size
|
479
513
|
end
|
480
514
|
|
481
515
|
return type_name
|
482
516
|
end
|
483
517
|
|
484
|
-
@@before_thread_id = nil
|
485
|
-
|
486
518
|
# Called at the start of the print method.
|
487
519
|
def self.print_start
|
488
|
-
if @@
|
489
|
-
|
490
|
-
return unless @@config.enabled?
|
520
|
+
if @@config == nil
|
521
|
+
initialize
|
491
522
|
end
|
523
|
+
return unless @@config.enabled?
|
492
524
|
|
493
525
|
thread = Thread.current
|
494
526
|
thread_id = thread.object_id
|
@@ -501,8 +533,6 @@ module DebugTrace
|
|
501
533
|
@@before_thread_id = thread_id
|
502
534
|
end
|
503
535
|
|
504
|
-
@@DO_NOT_OUTPUT = 'Do not output'
|
505
|
-
|
506
536
|
# Prints the message or the value.
|
507
537
|
#
|
508
538
|
# @param name [String] a message if the value is not specified, otherwise the value name
|
@@ -530,7 +560,7 @@ module DebugTrace
|
|
530
560
|
|
531
561
|
if value.equal? @@DO_NOT_OUTPUT
|
532
562
|
# without value
|
533
|
-
@@last_log_buff = LogBuffer.new(@@config.
|
563
|
+
@@last_log_buff = LogBuffer.new(@@config.data_output_width)
|
534
564
|
@@last_log_buff.no_break_append(name)
|
535
565
|
else
|
536
566
|
# with value
|
@@ -564,7 +594,7 @@ module DebugTrace
|
|
564
594
|
end
|
565
595
|
end
|
566
596
|
|
567
|
-
return value
|
597
|
+
return value.equal? @@DO_NOT_OUTPUT ? nil : value
|
568
598
|
end
|
569
599
|
|
570
600
|
# Prints the start of the method.
|
@@ -590,7 +620,7 @@ module DebugTrace
|
|
590
620
|
@@logger.print(indent_string) # Empty Line
|
591
621
|
end
|
592
622
|
|
593
|
-
@@last_log_buff = LogBuffer.new(@@config.
|
623
|
+
@@last_log_buff = LogBuffer.new(@@config.data_output_width)
|
594
624
|
@@last_log_buff.no_break_append(
|
595
625
|
format(@@config.enter_format, name, filename, lineno, parent_name, parent_filename, parent_lineno)
|
596
626
|
)
|
@@ -623,7 +653,7 @@ module DebugTrace
|
|
623
653
|
|
624
654
|
time = (Time.now.utc - state.down_nest) * 1000 # milliseconds <- seconds
|
625
655
|
|
626
|
-
@@last_log_buff = LogBuffer.new(@@config.
|
656
|
+
@@last_log_buff = LogBuffer.new(@@config.data_output_width)
|
627
657
|
@@last_log_buff.no_break_append(
|
628
658
|
format(@@config.leave_format, name, filename, lineno, time)
|
629
659
|
)
|
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: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masato Kokubo
|
@@ -20,10 +20,12 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- ".rubocop.yml"
|
22
22
|
- CHANGELOG.md
|
23
|
-
- LICENSE
|
23
|
+
- LICENSE.txt
|
24
24
|
- README.md
|
25
|
+
- README_ja.md
|
25
26
|
- Rakefile
|
26
|
-
- debugtrace.yml
|
27
|
+
- examples/debugtrace.yml
|
28
|
+
- examples/readme-example.rb
|
27
29
|
- lib/debugtrace.rb
|
28
30
|
- lib/debugtrace/common.rb
|
29
31
|
- lib/debugtrace/config.rb
|
@@ -53,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
55
|
- !ruby/object:Gem::Version
|
54
56
|
version: '0'
|
55
57
|
requirements: []
|
56
|
-
rubygems_version: 3.6.
|
58
|
+
rubygems_version: 3.6.9
|
57
59
|
specification_version: 4
|
58
60
|
summary: DebugTrace-rb is a library that helps debug ruby programs.
|
59
61
|
test_files: []
|
data/debugtrace.yml
DELETED
/data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|