debugtrace 0.2.6 → 0.3.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/LICENSE +1 -1
- data/debugtrace.yml +2 -0
- data/lib/debugtrace/common.rb +7 -5
- data/lib/debugtrace/config.rb +5 -2
- data/lib/debugtrace/log_buffer.rb +24 -11
- data/lib/debugtrace/loggers.rb +30 -12
- data/lib/debugtrace/state.rb +13 -6
- data/lib/debugtrace/version.rb +2 -2
- data/lib/debugtrace.rb +116 -46
- 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: d449ce280e070de6b2606264a7df4247bf2949788dbcf9e537b8ca7191cd91ba
|
4
|
+
data.tar.gz: 347ca320e082e30a706b8309cdb86876daa4779c7d0be8179576856c6d7a58e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f35b455465fa17bef9ce031a122d9f9695384a746c9eca1cbd8d838829f6837a010661e1594c62a58912d182d75144505cf935e37eaf4dfb5edef368c7554818
|
7
|
+
data.tar.gz: 07af66161e9949dad056316a405607ad435c115a65d46c6b33bc46196aebbf563b94345f92c29fa03b36a788929430a525ff90a87bb3de2e9558dd0846be4ac5
|
data/LICENSE
CHANGED
data/debugtrace.yml
ADDED
data/lib/debugtrace/common.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# common.rb
|
2
3
|
# (C) 2025 Masato Kokubo
|
3
4
|
|
4
5
|
# Defines commonly used functions.
|
5
|
-
# @author Masato Kokubo
|
6
6
|
module Common
|
7
7
|
# Check the value types.
|
8
|
+
#
|
8
9
|
# @param value_name [String] the value name
|
9
10
|
# @param value [String] the value
|
10
11
|
# @param type [Class] the type
|
11
|
-
# @
|
12
|
+
# @return [String] the value
|
13
|
+
# @raise [TypeError] if the value is not an instance of the type or the subclass of the type
|
12
14
|
def self.check_type(value_name, value, type)
|
13
|
-
raise "Argument value_name (=#{value_name}) must be a String" unless value_name.is_a?(String)
|
14
|
-
raise "Argument type (=#{type}) must be a Class" unless type.is_a?(Class)
|
15
|
+
raise TypeError("Argument value_name (=#{value_name}) must be a String") unless value_name.is_a?(String)
|
16
|
+
raise TypeError("Argument type (=#{type}) must be a Class") unless type.is_a?(Class)
|
15
17
|
|
16
18
|
error = false
|
17
19
|
if type == FalseClass || type == TrueClass
|
@@ -28,7 +30,7 @@ module Common
|
|
28
30
|
top_type_name = type.name.slice(0).upcase
|
29
31
|
a = top_type_name == 'A' || top_type_name == 'I' || top_type_name == 'U' ||
|
30
32
|
top_type_name == 'E' || top_type_name == 'O' ? 'an' : 'a'
|
31
|
-
raise "Argument #{value_name} (=#{value_string}) must be #{a} #{type}"
|
33
|
+
raise TypeError("Argument #{value_name} (=#{value_string}) must be #{a} #{type}")
|
32
34
|
end
|
33
35
|
return value
|
34
36
|
end
|
data/lib/debugtrace/config.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# config.rb
|
2
3
|
# (C) 2025 Masato Kokubo
|
3
4
|
require 'yaml'
|
4
5
|
require_relative 'common'
|
5
6
|
|
6
7
|
# Retains the contents defined in debugtrace.yml.
|
7
|
-
# @author Masato Kokubo
|
8
8
|
class Config
|
9
9
|
attr_reader :config_path
|
10
10
|
attr_reader :config
|
@@ -36,6 +36,7 @@ class Config
|
|
36
36
|
attr_reader :reflection_limit
|
37
37
|
|
38
38
|
# Initializes with a yml file in the config_path.
|
39
|
+
#
|
39
40
|
# @param config_path [String] path of the yml file
|
40
41
|
def initialize(config_path)
|
41
42
|
@config_path = Common.check_type('config_path', config_path, String)
|
@@ -75,7 +76,8 @@ class Config
|
|
75
76
|
end
|
76
77
|
|
77
78
|
# Returns true if logging is enabled, false otherwise.
|
78
|
-
#
|
79
|
+
#
|
80
|
+
# @return [TrueClass, FalseClass] true if logging is enabled, false otherwise
|
79
81
|
def enabled?
|
80
82
|
return @enabled
|
81
83
|
end
|
@@ -83,6 +85,7 @@ class Config
|
|
83
85
|
private
|
84
86
|
|
85
87
|
# Gets the value related the key from debugtrace.yml file.
|
88
|
+
#
|
86
89
|
# @param key [String] the key
|
87
90
|
# @param defalut_value [Object] value to return if the value related the key is undefined
|
88
91
|
# @return [Object] value related the key
|
@@ -1,19 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# log_buffer.rb
|
2
3
|
# (C) 2025 Masato Kokubo
|
3
4
|
require_relative 'common'
|
4
5
|
|
5
6
|
# Buffers logs.
|
6
|
-
# @author Masato Kokubo
|
7
7
|
class LogBuffer
|
8
|
+
# Contains a single line indentation level and log content.
|
8
9
|
class LevelAndLog
|
10
|
+
attr_reader :nest_level, :log
|
11
|
+
|
9
12
|
# Initializes this object.
|
13
|
+
#
|
14
|
+
# @param nest_level [Integer] the nesting level
|
15
|
+
# @param log [String] the log message
|
10
16
|
def initialize(nest_level, log)
|
11
17
|
@nest_level = Common.check_type('nest_level', nest_level, Integer)
|
12
18
|
@log = Common.check_type('log', log, String)
|
13
19
|
end
|
14
20
|
|
15
|
-
|
16
|
-
|
21
|
+
# Returns a string representation of this object.
|
22
|
+
#
|
23
|
+
# @return [String] a string representation of this object.
|
17
24
|
def to_s
|
18
25
|
return "(LogBuffer.LevelAndLog){nest_level: #{@nest_level}, log: \"#{@log}\"}"
|
19
26
|
end
|
@@ -50,11 +57,12 @@ class LogBuffer
|
|
50
57
|
end
|
51
58
|
|
52
59
|
# Appends a string representation of the value.
|
60
|
+
#
|
53
61
|
# @param value [Object] The value to append
|
54
62
|
# @param nest_level (int, optional): The nest level of the value. Defaults to 0
|
55
63
|
# @param no_break (bool, optional): If true, does not break even if the maximum width is exceeded.
|
56
64
|
# Defaults to false
|
57
|
-
# @return LogBuffer
|
65
|
+
# @return [LogBuffer] this object
|
58
66
|
def append(value, nest_level = 0, no_break = false)
|
59
67
|
Common.check_type('nest_level', nest_level, Integer)
|
60
68
|
Common.check_type('no_break', no_break, TrueClass)
|
@@ -69,17 +77,18 @@ class LogBuffer
|
|
69
77
|
|
70
78
|
# Appends a string representation of the value.
|
71
79
|
# Does not break even if the maximum width is exceeded.
|
80
|
+
#
|
72
81
|
# @param value [Object] The value to append
|
73
|
-
# @return LogBuffer
|
82
|
+
# @return [LogBuffer] this object
|
74
83
|
def no_break_append(value)
|
75
84
|
return append(value, 0, true)
|
76
85
|
end
|
77
86
|
|
78
87
|
# Appends lines of another LogBuffer.
|
79
|
-
#
|
80
|
-
# @param separator [String]
|
81
|
-
# @param buff
|
82
|
-
# @
|
88
|
+
#
|
89
|
+
# @param separator [String] the separator string to append if not ''
|
90
|
+
# @param buff [LogBuffer] another LogBuffer
|
91
|
+
# @return [LogBuffer] this object
|
83
92
|
def append_buffer(separator, buff)
|
84
93
|
Common.check_type('separator', separator, String)
|
85
94
|
Common.check_type('buff', buff, LogBuffer)
|
@@ -98,12 +107,16 @@ class LogBuffer
|
|
98
107
|
return @last_line.length
|
99
108
|
end
|
100
109
|
|
101
|
-
# true if multiple line, false otherwise.
|
110
|
+
# Returns true if multiple line, false otherwise.
|
111
|
+
#
|
112
|
+
# @return [FalseClass, TrueClass] true if multiple line, false otherwise.
|
102
113
|
def multi_lines?
|
103
114
|
return @lines.length > 1 || @lines.length == 1 && length > 0
|
104
115
|
end
|
105
116
|
|
106
|
-
#
|
117
|
+
# Returns the LevelAndLog objects.
|
118
|
+
#
|
119
|
+
# @return [Array<LevelAndLog>] the LevelAndLog objects.
|
107
120
|
def lines
|
108
121
|
lines = @lines.dup
|
109
122
|
lines << LevelAndLog.new(@nest_level, @last_line) if length > 0
|
data/lib/debugtrace/loggers.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# loggers.rb
|
2
3
|
# (C) 2023 Masato Kokubo
|
3
4
|
require 'logger'
|
4
5
|
require_relative 'common'
|
5
6
|
require_relative 'config'
|
6
7
|
|
7
|
-
#
|
8
|
-
# @author Masato Kokubo
|
8
|
+
# @abstract Base class for logger classes.
|
9
9
|
class LoggerBase
|
10
|
-
# Outputs the message.
|
10
|
+
# @abstract Outputs the message.
|
11
11
|
# @param message [String] The message to output
|
12
|
+
# @raise [Exception] always
|
12
13
|
def print(message)
|
13
|
-
raise 'LoggerBase.print is an abstract method.'
|
14
|
+
raise Exception.new('LoggerBase.print is an abstract method.')
|
14
15
|
end
|
15
16
|
|
16
17
|
# Returns a string representation of this object.
|
@@ -23,18 +24,19 @@ end
|
|
23
24
|
# Abstract base class for StdOut and StdErr classes.
|
24
25
|
class StdLogger < LoggerBase
|
25
26
|
# Initializes this object.
|
26
|
-
# @param
|
27
|
-
def initialize(config,
|
27
|
+
# @param [IO] Output destination
|
28
|
+
def initialize(config, output)
|
28
29
|
@config = Common::check_type("config", config, Config)
|
29
|
-
@
|
30
|
+
@output = output
|
30
31
|
end
|
31
32
|
|
32
33
|
# Outputs the message.
|
33
|
-
# @param message [String]
|
34
|
+
# @param message [String] the message to output
|
35
|
+
# @return [String] the message
|
34
36
|
def print(message)
|
35
37
|
Common::check_type("message", message, String)
|
36
38
|
datetime_str = Time.now().strftime(@config.logging_datetime_format)
|
37
|
-
@
|
39
|
+
@output.puts "#{datetime_str} #{message}"
|
38
40
|
end
|
39
41
|
|
40
42
|
end
|
@@ -42,6 +44,7 @@ end
|
|
42
44
|
# A logger class that outputs to $stdout.
|
43
45
|
class StdOutLogger < StdLogger
|
44
46
|
# Initializes this object.
|
47
|
+
# config [Config] a configuration object
|
45
48
|
def initialize(config)
|
46
49
|
super(config, $stdout)
|
47
50
|
end
|
@@ -50,18 +53,21 @@ end
|
|
50
53
|
# A logger class that outputs to $stderr.
|
51
54
|
class StdErrLogger < StdLogger
|
52
55
|
# Initializes this object.
|
56
|
+
# config [Config] a configuration object
|
53
57
|
def initialize(config)
|
54
58
|
super(config, $stderr)
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
58
|
-
# A logger class that outputs using
|
62
|
+
# A logger class that outputs using Ruby Logger.
|
59
63
|
class RubyLogger
|
60
64
|
private
|
61
65
|
|
62
66
|
class Formatter
|
67
|
+
# Initializes this object.
|
68
|
+
# config [Config] a configuration object
|
63
69
|
def initialize(config)
|
64
|
-
@config = config
|
70
|
+
@config = Common::check_type("config", config, Config)
|
65
71
|
end
|
66
72
|
|
67
73
|
def call(severity, datetime, progname, msg)
|
@@ -72,6 +78,9 @@ class RubyLogger
|
|
72
78
|
|
73
79
|
public
|
74
80
|
|
81
|
+
# Initializes this object.
|
82
|
+
#
|
83
|
+
# @param config [Config] a configuration object
|
75
84
|
def initialize(config)
|
76
85
|
@config = Common::check_type("config", config, Config)
|
77
86
|
@logger = Logger.new(
|
@@ -81,6 +90,7 @@ class RubyLogger
|
|
81
90
|
end
|
82
91
|
|
83
92
|
# Outputs the message.
|
93
|
+
#
|
84
94
|
# @param message [String] The message to output
|
85
95
|
def print(message)
|
86
96
|
Common::check_type("message", message, String)
|
@@ -89,6 +99,7 @@ class RubyLogger
|
|
89
99
|
end
|
90
100
|
|
91
101
|
# Returns a string representation of this object.
|
102
|
+
#
|
92
103
|
# @return [String] A string representation of this object
|
93
104
|
def to_s
|
94
105
|
return "Ruby #{Logger.name} path: #{@config.log_path}"
|
@@ -99,6 +110,9 @@ end
|
|
99
110
|
class FileLogger < LoggerBase
|
100
111
|
@@log_path_default = 'debugtrace.log'
|
101
112
|
|
113
|
+
# Initializes this object.
|
114
|
+
#
|
115
|
+
# @parm config [Config] a configuration object
|
102
116
|
def initialize(config)
|
103
117
|
@log_path = @@log_path_default
|
104
118
|
@config = Common::check_type("config", config, Config)
|
@@ -125,8 +139,11 @@ class FileLogger < LoggerBase
|
|
125
139
|
end
|
126
140
|
end
|
127
141
|
|
142
|
+
# Outputs the message.
|
143
|
+
#
|
144
|
+
# @param message [String] the message to output
|
145
|
+
# @return [String] the message
|
128
146
|
def print(message)
|
129
|
-
# Common::check_type("message", message, String)
|
130
147
|
if File.exist?(@log_path)
|
131
148
|
File.open(@log_path, 'a') { |file|
|
132
149
|
datetime_str = Time.now().strftime(@config.logging_datetime_format)
|
@@ -137,6 +154,7 @@ class FileLogger < LoggerBase
|
|
137
154
|
end
|
138
155
|
|
139
156
|
# Returns a string representation of this object.
|
157
|
+
#
|
140
158
|
# @return [String] A string representation of this object
|
141
159
|
def to_s
|
142
160
|
return "#{self.class.name} path: #{@log_path}, append: #{@append}"
|
data/lib/debugtrace/state.rb
CHANGED
@@ -1,25 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# state.rb
|
2
3
|
# (C) 2025 Masato Kokubo
|
3
4
|
require_relative 'common'
|
4
5
|
|
5
|
-
#
|
6
|
-
# @author Masato Kokubo
|
6
|
+
# Contains the trace state for a thread
|
7
7
|
class State
|
8
8
|
attr_reader :thread_id
|
9
9
|
attr_reader :nest_level
|
10
10
|
attr_reader :previous_nest_level
|
11
11
|
|
12
|
+
# Initializes this object.
|
13
|
+
#
|
14
|
+
# @param thread_id [Integer] the object id of the thread
|
12
15
|
def initialize(thread_id)
|
13
|
-
@thread_id = thread_id
|
16
|
+
@thread_id = Common.check_type('thread_id', thread_id, Integer)
|
14
17
|
reset()
|
15
18
|
end
|
16
19
|
|
20
|
+
# Resets this object
|
17
21
|
def reset
|
18
22
|
@nest_level = 0
|
19
23
|
@previous_nest_level = 0
|
20
24
|
@times = []
|
21
25
|
end
|
22
26
|
|
27
|
+
# Returns a string representation of this object.
|
28
|
+
#
|
29
|
+
# @return [String] A string representation of this object
|
23
30
|
def to_s()
|
24
31
|
return "(State){thread_id: #{@thread_id}, nest_level: #{@nest_level}, previous_nest_level: #{@previous_nest_level}, times: #{@times}}"
|
25
32
|
end
|
@@ -31,11 +38,11 @@ class State
|
|
31
38
|
@times.push(Time.now)
|
32
39
|
end
|
33
40
|
@nest_level += 1
|
34
|
-
return nil
|
35
41
|
end
|
36
42
|
|
37
|
-
#Downs the nest level.
|
38
|
-
#
|
43
|
+
# Downs the nest level.
|
44
|
+
#
|
45
|
+
# @return [Float] The time when the corresponding up_nest method was invoked
|
39
46
|
def down_nest
|
40
47
|
@previous_nest_level = @nest_level
|
41
48
|
@nest_level -= 1
|
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'
|
@@ -10,7 +13,7 @@ require_relative 'debugtrace/log_buffer'
|
|
10
13
|
require_relative 'debugtrace/loggers'
|
11
14
|
require_relative 'debugtrace/state'
|
12
15
|
|
13
|
-
#
|
16
|
+
# The main module of DebugTrace-rb.
|
14
17
|
module DebugTrace
|
15
18
|
# Configuration values
|
16
19
|
@@config = nil
|
@@ -37,6 +40,9 @@ module DebugTrace
|
|
37
40
|
# The logger used by DebugTrace-py
|
38
41
|
@@logger = nil
|
39
42
|
|
43
|
+
# Initialize this class
|
44
|
+
#
|
45
|
+
# @option [String] config_path the path to the configuration file. ./debugtrace.yml if not specified.
|
40
46
|
def self.initialize(config_path = './debugtrace.yml')
|
41
47
|
@@config = Config.new(config_path)
|
42
48
|
|
@@ -65,11 +71,22 @@ module DebugTrace
|
|
65
71
|
@@logger.print(" logger: #{@@logger}")
|
66
72
|
end
|
67
73
|
|
74
|
+
# Contains options to pass to the print method.
|
68
75
|
class PrintOptions
|
69
|
-
attr_reader :minimum_output_size, :minimum_output_length,
|
76
|
+
attr_reader :reflection, :minimum_output_size, :minimum_output_length,
|
70
77
|
:collection_limit, :bytes_limit, :string_limit, :reflection_limit
|
71
78
|
|
79
|
+
# Initializes this object.
|
80
|
+
#
|
81
|
+
# @param reflection [TrueClass, FalseClass] use reflection if true
|
82
|
+
# @param minimum_output_size [Integer] the minimum value to output the number of elements for Array and Hash (overrides debugtarace.yml value)
|
83
|
+
# @param minimum_output_length [Integer] the minimum value to output the length of String and byte array (overrides debugtarace.yml value)
|
84
|
+
# @param collection_limit [Integer] Output limit of collection elements (overrides debugtarace.yml value)
|
85
|
+
# @param bytes_limit [Integer] the limit value of elements for bytes and bytearray to output (overrides debugtarace.yml value)
|
86
|
+
# @param string_limit [Integer] the limit value of characters for string to output (overrides debugtarace.yml value)
|
87
|
+
# @param reflection_limit [Integer] reflection limits when using reflection (overrides debugtarace.yml value)
|
72
88
|
def initialize(
|
89
|
+
reflection,
|
73
90
|
minimum_output_size,
|
74
91
|
minimum_output_length,
|
75
92
|
collection_limit,
|
@@ -77,6 +94,7 @@ module DebugTrace
|
|
77
94
|
string_limit,
|
78
95
|
reflection_limit
|
79
96
|
)
|
97
|
+
@reflection = reflection
|
80
98
|
@minimum_output_size = minimum_output_size == -1 ? DebugTrace.config.minimum_output_size : minimum_output_size
|
81
99
|
@minimum_output_length = minimum_output_length == -1 ? DebugTrace.config.minimum_output_length : minimum_output_length
|
82
100
|
@collection_limit = collection_limit == -1 ? DebugTrace.config.collection_limit : collection_limit
|
@@ -86,6 +104,9 @@ module DebugTrace
|
|
86
104
|
end
|
87
105
|
end
|
88
106
|
|
107
|
+
# Returns the current state.
|
108
|
+
#
|
109
|
+
# @return [State] the current state
|
89
110
|
def self.current_state
|
90
111
|
thread_id = Thread.current.object_id
|
91
112
|
|
@@ -99,12 +120,22 @@ module DebugTrace
|
|
99
120
|
return state
|
100
121
|
end
|
101
122
|
|
123
|
+
# Returns the current indent string.
|
124
|
+
#
|
125
|
+
# @param nest_level [Integer] the code nesting level
|
126
|
+
# @param data_nest_level [Integer] the data nesting level
|
127
|
+
# @return [Sring] the current indent string
|
102
128
|
def self.get_indent_string(nest_level, data_nest_level)
|
103
129
|
indent_str = @@config.indent_string * [[0, nest_level].max, @@config.maximum_indents].min
|
104
130
|
data_indent_str = @@config.data_indent_string * [[0, data_nest_level].max, @@config.maximum_indents].min
|
105
131
|
return indent_str + data_indent_str
|
106
132
|
end
|
107
133
|
|
134
|
+
# Returns a string representation of the variable contents.
|
135
|
+
#
|
136
|
+
# @param name [String] the variable name
|
137
|
+
# @param value [Object] the value
|
138
|
+
# @param print_options [PrintOptions] the print options
|
108
139
|
def self.to_string(name, value, print_options)
|
109
140
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
110
141
|
|
@@ -126,7 +157,8 @@ module DebugTrace
|
|
126
157
|
when Module
|
127
158
|
buff.no_break_append(separator).append(value.name).no_break_append(' module')
|
128
159
|
when String
|
129
|
-
value_buff =
|
160
|
+
value_buff = value.encoding == Encoding::ASCII_8BIT ?
|
161
|
+
to_string_bytes(value, print_options) : to_string_str(value, print_options)
|
130
162
|
buff.append_buffer(separator, value_buff)
|
131
163
|
when DateTime
|
132
164
|
buff.no_break_append(separator).append(value.strftime('%Y-%m-%d %H:%M-%S.%L%:z'))
|
@@ -138,28 +170,35 @@ module DebugTrace
|
|
138
170
|
value_buff = to_string_enumerable(value, print_options)
|
139
171
|
buff.append_buffer(separator, value_buff)
|
140
172
|
else
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
173
|
+
if print_options.reflection
|
174
|
+
# use reflection
|
175
|
+
value_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
176
|
+
if @@reflected_objects.any? { |obj| value.equal?(obj) }
|
177
|
+
# cyclic reference
|
178
|
+
value_buff.no_break_append(@@config.cyclic_reference_string)
|
179
|
+
elsif @@reflected_objects.length > print_options.reflection_limit
|
180
|
+
# over reflection level limitation
|
181
|
+
value_buff.no_break_append(@@config.limit_string)
|
182
|
+
else
|
183
|
+
@@reflected_objects.push(value)
|
184
|
+
value_buff = to_string_reflection(value, print_options)
|
185
|
+
@@reflected_objects.pop
|
186
|
+
end
|
187
|
+
buff.append_buffer(separator, value_buff)
|
149
188
|
else
|
150
|
-
|
151
|
-
value_buff = to_string_reflection(value, print_options)
|
152
|
-
@@reflected_objects.pop
|
189
|
+
buff.no_break_append(separator).append(value.to_s)
|
153
190
|
end
|
154
|
-
buff.append_buffer(separator, value_buff)
|
155
191
|
end
|
156
192
|
|
157
193
|
return buff
|
158
194
|
end
|
159
195
|
|
196
|
+
# Returns a string representation of the string value
|
197
|
+
#
|
198
|
+
# @param value [String] the value
|
199
|
+
# @param print_options [PrintOptions] the print options
|
160
200
|
def self.to_string_str(value, print_options)
|
161
|
-
|
162
|
-
has_double_quote = false
|
201
|
+
double_quote = false
|
163
202
|
single_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
164
203
|
double_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
165
204
|
|
@@ -180,30 +219,28 @@ module DebugTrace
|
|
180
219
|
end
|
181
220
|
case char
|
182
221
|
when "'"
|
183
|
-
|
222
|
+
double_quote = true
|
184
223
|
double_quote_buff.no_break_append(char)
|
185
|
-
has_single_quote = true
|
186
224
|
when '"'
|
187
225
|
single_quote_buff.no_break_append(char)
|
188
226
|
double_quote_buff.no_break_append("\\\"")
|
189
|
-
has_double_quote = true
|
190
227
|
when "\\"
|
191
|
-
|
228
|
+
double_quote = true
|
192
229
|
double_quote_buff.no_break_append("\\\\")
|
193
230
|
when "\n"
|
194
|
-
|
231
|
+
double_quote = true
|
195
232
|
double_quote_buff.no_break_append("\\n")
|
196
233
|
when "\r"
|
197
|
-
|
234
|
+
double_quote = true
|
198
235
|
double_quote_buff.no_break_append("\\r")
|
199
236
|
when "\t"
|
200
|
-
|
237
|
+
double_quote = true
|
201
238
|
double_quote_buff.no_break_append("\\t")
|
202
239
|
else
|
203
240
|
char_ord = char.ord
|
204
241
|
if char_ord >= 0x00 && char_ord <= 0x1F || char_ord == 0x7F
|
242
|
+
double_quote = true
|
205
243
|
num_str = format('%02X', char_ord)
|
206
|
-
single_quote_buff.no_break_append("\\x" + num_str)
|
207
244
|
double_quote_buff.no_break_append("\\x" + num_str)
|
208
245
|
else
|
209
246
|
single_quote_buff.no_break_append(char)
|
@@ -216,19 +253,16 @@ module DebugTrace
|
|
216
253
|
double_quote_buff.no_break_append('"')
|
217
254
|
single_quote_buff.no_break_append("'")
|
218
255
|
|
219
|
-
return
|
256
|
+
return double_quote ? double_quote_buff : single_quote_buff
|
220
257
|
end
|
221
258
|
|
259
|
+
# Returns a string representation of the string value which encoding is ASCII_8BIT.
|
260
|
+
#
|
261
|
+
# @param value [String] the value
|
262
|
+
# @param print_options [PrintOptions] the print options
|
222
263
|
def self.to_string_bytes(value, print_options)
|
223
264
|
bytes_length = value.length
|
224
265
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
225
|
-
buff.no_break_append('(')
|
226
|
-
|
227
|
-
if value.is_a?(String)
|
228
|
-
buff.no_break_append('bytes')
|
229
|
-
elsif value.is_a?(Array)
|
230
|
-
buff.no_break_append('bytearray')
|
231
|
-
end
|
232
266
|
|
233
267
|
if bytes_length >= @@config.minimum_output_length
|
234
268
|
buff.no_break_append(format(@@config.size_format, bytes_length))
|
@@ -280,6 +314,10 @@ module DebugTrace
|
|
280
314
|
return buff
|
281
315
|
end
|
282
316
|
|
317
|
+
# Returns a string representation of the value using reflection.
|
318
|
+
#
|
319
|
+
# @param value [Object] the value
|
320
|
+
# @param print_options [PrintOptions] the print options
|
283
321
|
def self.to_string_reflection(value, print_options)
|
284
322
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
285
323
|
|
@@ -306,6 +344,10 @@ module DebugTrace
|
|
306
344
|
return buff
|
307
345
|
end
|
308
346
|
|
347
|
+
# Returns a string representation of the value using reflection.
|
348
|
+
#
|
349
|
+
# @param value [Object] the value
|
350
|
+
# @param print_options [PrintOptions] the print options
|
309
351
|
def self.to_string_reflection_body(value, print_options)
|
310
352
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
311
353
|
|
@@ -330,6 +372,10 @@ module DebugTrace
|
|
330
372
|
return buff
|
331
373
|
end
|
332
374
|
|
375
|
+
# Returns a string representation of an Array, Set or Hash.
|
376
|
+
#
|
377
|
+
# @param value [Array, Set, Hash] the value
|
378
|
+
# @param print_options [PrintOptions] the print options
|
333
379
|
def self.to_string_enumerable(values, print_options)
|
334
380
|
open_char = '[' # Array
|
335
381
|
close_char = ']'
|
@@ -369,6 +415,10 @@ module DebugTrace
|
|
369
415
|
return buff
|
370
416
|
end
|
371
417
|
|
418
|
+
# Returns a string representation of the Array, Set or Hash value.
|
419
|
+
#
|
420
|
+
# @param value [Array, Set, Hash] the value
|
421
|
+
# @param print_options [PrintOptions] the print options
|
372
422
|
def self.to_string_enumerable_body(values, print_options)
|
373
423
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
374
424
|
|
@@ -403,6 +453,11 @@ module DebugTrace
|
|
403
453
|
return buff
|
404
454
|
end
|
405
455
|
|
456
|
+
# Returns a string representation the key and the value.
|
457
|
+
#
|
458
|
+
# @param key [Object] the key
|
459
|
+
# @param value [Object] the value
|
460
|
+
# @param print_options [PrintOptions] the print options
|
406
461
|
def self.to_string_key_value(key, value, print_options)
|
407
462
|
buff = LogBuffer.new(@@config.maximum_data_output_width)
|
408
463
|
key_buff = to_string('', key, print_options)
|
@@ -411,28 +466,24 @@ module DebugTrace
|
|
411
466
|
buff
|
412
467
|
end
|
413
468
|
|
414
|
-
|
469
|
+
# Returns the type name.
|
470
|
+
#
|
471
|
+
# @param value [Object] the value
|
472
|
+
# @option size [Object] the size of Array, Set or Hash
|
473
|
+
def self.get_type_name(value, size = -1)
|
415
474
|
type_name = value.class.to_s
|
416
475
|
type_name = '' if %w[Array Hash Set].include?(type_name)
|
417
476
|
|
418
|
-
if
|
419
|
-
type_name += @@config.size_format %
|
477
|
+
if size >= @@config.minimum_output_size
|
478
|
+
type_name += @@config.size_format % size
|
420
479
|
end
|
421
480
|
|
422
481
|
return type_name
|
423
482
|
end
|
424
483
|
|
425
|
-
def self.has_to_s_method?(value)
|
426
|
-
begin
|
427
|
-
value.public_method('to_s')
|
428
|
-
rescue
|
429
|
-
return false
|
430
|
-
end
|
431
|
-
return true
|
432
|
-
end
|
433
|
-
|
434
484
|
@@before_thread_id = nil
|
435
485
|
|
486
|
+
# Called at the start of the print method.
|
436
487
|
def self.print_start
|
437
488
|
if @@before_thread_id == nil
|
438
489
|
DebugTrace.initialize
|
@@ -452,7 +503,19 @@ module DebugTrace
|
|
452
503
|
|
453
504
|
@@DO_NOT_OUTPUT = 'Do not output'
|
454
505
|
|
506
|
+
# Prints the message or the value.
|
507
|
+
#
|
508
|
+
# @param name [String] a message if the value is not specified, otherwise the value name
|
509
|
+
# @option value [Object] the value
|
510
|
+
# @option reflection [TrueClass, FalseClass] use reflection if true
|
511
|
+
# @option minimum_output_size [Integer] the minimum value to output the number of elements for Array and Hash (overrides debugtarace.yml value)
|
512
|
+
# @option minimum_output_length [Integer] the minimum value to output the length of String and byte array (overrides debugtarace.yml value)
|
513
|
+
# @option collection_limit [Integer] Output limit of collection elements (overrides debugtarace.yml value)
|
514
|
+
# @option bytes_limit [Integer] the limit value of elements for bytes and bytearray to output (overrides debugtarace.yml value)
|
515
|
+
# @option string_limit [Integer] the limit value of characters for string to output (overrides debugtarace.yml value)
|
516
|
+
# @option reflection_limit [Integer] reflection limits when using reflection (overrides debugtarace.yml value)
|
455
517
|
def self.print(name, value = @@DO_NOT_OUTPUT,
|
518
|
+
reflection: false,
|
456
519
|
minimum_output_size: -1, minimum_output_length: -1,
|
457
520
|
collection_limit: -1, bytes_limit: -1,
|
458
521
|
string_limit: -1, reflection_limit: -1)
|
@@ -472,6 +535,7 @@ module DebugTrace
|
|
472
535
|
else
|
473
536
|
# with value
|
474
537
|
print_options = PrintOptions.new(
|
538
|
+
reflection,
|
475
539
|
minimum_output_size, minimum_output_length,
|
476
540
|
collection_limit, bytes_limit,
|
477
541
|
string_limit, reflection_limit
|
@@ -503,6 +567,7 @@ module DebugTrace
|
|
503
567
|
return value
|
504
568
|
end
|
505
569
|
|
570
|
+
# Prints the start of the method.
|
506
571
|
def self.enter
|
507
572
|
@@thread_mutex.synchronize do
|
508
573
|
print_start
|
@@ -536,6 +601,10 @@ module DebugTrace
|
|
536
601
|
end
|
537
602
|
end
|
538
603
|
|
604
|
+
# Prints the end of the method.
|
605
|
+
#
|
606
|
+
# @option [Object] the return value
|
607
|
+
# @return [Object] return_value if specified, otherwise nil
|
539
608
|
def self.leave(return_value = nil)
|
540
609
|
@@thread_mutex.synchronize do
|
541
610
|
print_start
|
@@ -564,9 +633,10 @@ module DebugTrace
|
|
564
633
|
end
|
565
634
|
end
|
566
635
|
|
636
|
+
# Returns the last print string.
|
567
637
|
def self.last_print_string
|
568
638
|
lines = @@last_log_buff.lines
|
569
|
-
buff_string = lines.map { |line|
|
639
|
+
buff_string = lines.map { |line| @@config.data_indent_string * line.nest_level + line.log }.join("\n")
|
570
640
|
|
571
641
|
state = nil
|
572
642
|
@@thread_mutex.synchronize do
|
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.0
|
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
|