debugtrace 0.2.1 → 0.2.3
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/lib/debugtrace/config.rb +57 -36
- data/lib/debugtrace/loggers.rb +37 -27
- data/lib/debugtrace/version.rb +1 -1
- data/lib/debugtrace.rb +20 -31
- 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: 573b6a776aab4ba5ffcd8b5f5b5c62c93250c9a637c11ee455325e79013b6243
|
4
|
+
data.tar.gz: 23f331e71a62a005ce75eb2e966fcafda2854d8ff73d42f6e399328df84deac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60707f1a062650f909b2a6f194a55edc0ad546823ea91f226b90b15dc943cd0157159bcde691ba5bae795fa3ad08698e5a6e6dfe139a6fbdd61087b74a1d06f2
|
7
|
+
data.tar.gz: 474b9c3cdfee32220b5bd182d14446c4762bd0e2d807dba3710ff797c653beb61087cffd2eb380fa3b9e28c8a6e0afcb87af82e28fed6caca78294bbc12f7b38
|
data/lib/debugtrace/config.rb
CHANGED
@@ -4,6 +4,35 @@ require 'yaml'
|
|
4
4
|
require_relative 'common'
|
5
5
|
|
6
6
|
class Config
|
7
|
+
attr_reader :config
|
8
|
+
attr_reader :config_path
|
9
|
+
attr_reader :logger_name
|
10
|
+
attr_reader :log_path
|
11
|
+
attr_reader :logging_format
|
12
|
+
attr_reader :logging_datetime_format
|
13
|
+
attr_reader :enter_format
|
14
|
+
attr_reader :leave_format
|
15
|
+
attr_reader :thread_boundary_format
|
16
|
+
attr_reader :maximum_indents
|
17
|
+
attr_reader :indent_string
|
18
|
+
attr_reader :data_indent_string
|
19
|
+
attr_reader :limit_string
|
20
|
+
attr_reader :non_output_string
|
21
|
+
attr_reader :cyclic_reference_string
|
22
|
+
attr_reader :varname_value_separator
|
23
|
+
attr_reader :key_value_separator
|
24
|
+
attr_reader :print_suffix_format
|
25
|
+
attr_reader :count_format
|
26
|
+
attr_reader :minimum_output_count
|
27
|
+
attr_reader :length_format
|
28
|
+
attr_reader :minimum_output_length
|
29
|
+
attr_reader :maximum_data_output_width
|
30
|
+
attr_reader :bytes_count_in_line
|
31
|
+
attr_reader :collection_limit
|
32
|
+
attr_reader :bytes_limit
|
33
|
+
attr_reader :string_limit
|
34
|
+
attr_reader :reflection_limit
|
35
|
+
|
7
36
|
def initialize(config_path)
|
8
37
|
@config_path = Common.check_type('config_path', config_path, String)
|
9
38
|
if File.exist?(@config_path)
|
@@ -12,43 +41,35 @@ class Config
|
|
12
41
|
@config_path = '<No config file>'
|
13
42
|
@config = nil
|
14
43
|
end
|
15
|
-
@logger_name =
|
16
|
-
@
|
17
|
-
@logging_format =
|
18
|
-
@logging_datetime_format =
|
19
|
-
@enabled =
|
20
|
-
@enter_format =
|
21
|
-
@leave_format =
|
22
|
-
@thread_boundary_format =
|
23
|
-
@maximum_indents =
|
24
|
-
@indent_string =
|
25
|
-
@data_indent_string =
|
26
|
-
@limit_string =
|
27
|
-
@non_output_string =
|
28
|
-
@cyclic_reference_string =
|
29
|
-
@varname_value_separator =
|
30
|
-
@key_value_separator =
|
31
|
-
@print_suffix_format =
|
32
|
-
@count_format =
|
33
|
-
@minimum_output_count =
|
34
|
-
@length_format =
|
35
|
-
@minimum_output_length =
|
36
|
-
@maximum_data_output_width =
|
37
|
-
@bytes_count_in_line =
|
38
|
-
@collection_limit =
|
39
|
-
@bytes_limit =
|
40
|
-
@string_limit =
|
41
|
-
@reflection_limit =
|
44
|
+
@logger_name = get_value 'logger' , 'stderr'
|
45
|
+
@log_path = get_value 'log_path' , 'debugtrace.log'
|
46
|
+
@logging_format = get_value 'logging_format' , "%2$s %1$s %4$s\n"
|
47
|
+
@logging_datetime_format = get_value 'logging_datetime_format' , '%Y-%m-%d %H:%M:%S.%L%:z'
|
48
|
+
@enabled = get_value 'enabled' , true
|
49
|
+
@enter_format = get_value 'enter_format' , 'Enter %1$s (%2$s:%3$d) <- %4$s (%5$s:%6$d)'
|
50
|
+
@leave_format = get_value 'leave_format' , 'Leave %1$s (%2$s:%3$d) duration: %4$.3f ms'
|
51
|
+
@thread_boundary_format = get_value 'thread_boundary_format' , '______________________________ %1$s #%2$s ______________________________'
|
52
|
+
@maximum_indents = get_value 'maximum_indents' , 32
|
53
|
+
@indent_string = get_value 'indent_string' , '| '
|
54
|
+
@data_indent_string = get_value 'data_indent_string' , ' '
|
55
|
+
@limit_string = get_value 'limit_string' , '...'
|
56
|
+
@non_output_string = get_value 'non_output_string' , '...'
|
57
|
+
@cyclic_reference_string = get_value 'cyclic_reference_string' , '*** Cyclic Reference ***'
|
58
|
+
@varname_value_separator = get_value 'varname_value_separator' , ' = '
|
59
|
+
@key_value_separator = get_value 'key_value_separator' , ': '
|
60
|
+
@print_suffix_format = get_value 'print_suffix_format' , ' (%2$s:%3$d)'
|
61
|
+
@count_format = get_value 'count_format' , 'count:%d'
|
62
|
+
@minimum_output_count = get_value 'minimum_output_count' , 16
|
63
|
+
@length_format = get_value 'length_format' , 'length:%d'
|
64
|
+
@minimum_output_length = get_value 'minimum_output_length' , 16
|
65
|
+
@maximum_data_output_width = get_value 'maximum_data_output_width', 70
|
66
|
+
@bytes_count_in_line = get_value 'bytes_count_in_line' , 16
|
67
|
+
@collection_limit = get_value 'collection_limit' , 128
|
68
|
+
@bytes_limit = get_value 'bytes_limit' , 256
|
69
|
+
@string_limit = get_value 'string_limit' , 256
|
70
|
+
@reflection_limit = get_value 'reflection_limit' , 4
|
42
71
|
end
|
43
72
|
|
44
|
-
attr_reader :config_path, :logger_name, :logging_destination, :logging_format, :logging_datetime_format,
|
45
|
-
:enter_format, :leave_format, :thread_boundary_format, :maximum_indents,
|
46
|
-
:indent_string, :data_indent_string, :limit_string, :non_output_string,
|
47
|
-
:cyclic_reference_string, :varname_value_separator, :key_value_separator,
|
48
|
-
:print_suffix_format, :count_format, :minimum_output_count, :length_format,
|
49
|
-
:minimum_output_length, :maximum_data_output_width, :bytes_count_in_line,
|
50
|
-
:collection_limit, :bytes_limit, :string_limit, :reflection_limit
|
51
|
-
|
52
73
|
def enabled? = @enabled
|
53
74
|
|
54
75
|
private
|
@@ -57,7 +78,7 @@ class Config
|
|
57
78
|
# @param key (String): The key
|
58
79
|
# @param defalut_value (Object): Value to return when the value related the key is undefined
|
59
80
|
# @return Object: Value related the key
|
60
|
-
def
|
81
|
+
def get_value(key, defalut_value)
|
61
82
|
Common.check_type('key', key, String)
|
62
83
|
value = defalut_value
|
63
84
|
unless @config.nil?
|
data/lib/debugtrace/loggers.rb
CHANGED
@@ -11,6 +11,12 @@ class LoggerBase
|
|
11
11
|
def print(message)
|
12
12
|
raise 'LoggerBase.print is an abstract method.'
|
13
13
|
end
|
14
|
+
|
15
|
+
# Returns a string representation of this object.
|
16
|
+
# @return String: A string representation of this object
|
17
|
+
def to_s
|
18
|
+
"#{self.class.name}"
|
19
|
+
end
|
14
20
|
end
|
15
21
|
|
16
22
|
# Abstract base class for StdOut and StdErr classes.
|
@@ -38,12 +44,6 @@ class StdOutLogger < StdLogger
|
|
38
44
|
def initialize(config)
|
39
45
|
super(config, $stdout)
|
40
46
|
end
|
41
|
-
|
42
|
-
# Returns a string representation of this object.
|
43
|
-
# @return String: A string representation of this object
|
44
|
-
def to_s
|
45
|
-
'$stdout logger'
|
46
|
-
end
|
47
47
|
end
|
48
48
|
|
49
49
|
# A logger class that outputs to $stderr.
|
@@ -52,16 +52,10 @@ class StdErrLogger < StdLogger
|
|
52
52
|
def initialize(config)
|
53
53
|
super(config, $stderr)
|
54
54
|
end
|
55
|
-
|
56
|
-
# Returns a string representation of this object.
|
57
|
-
# @return String: A string representation of this object
|
58
|
-
def to_s
|
59
|
-
'$stderr logger'
|
60
|
-
end
|
61
55
|
end
|
62
56
|
|
63
57
|
# A logger class that outputs using the logging library.
|
64
|
-
class
|
58
|
+
class RubyLogger
|
65
59
|
private
|
66
60
|
|
67
61
|
class Formatter
|
@@ -80,7 +74,7 @@ class LoggerLogger
|
|
80
74
|
def initialize(config)
|
81
75
|
@config = Common::check_type("config", config, Config)
|
82
76
|
@logger = Logger.new(
|
83
|
-
@config.
|
77
|
+
@config.log_path,
|
84
78
|
formatter: Formatter.new(@config),
|
85
79
|
datetime_format: @config.logging_datetime_format)
|
86
80
|
end
|
@@ -95,28 +89,44 @@ class LoggerLogger
|
|
95
89
|
# Returns a string representation of this object.
|
96
90
|
# @return String: A string representation of this object
|
97
91
|
def to_s
|
98
|
-
|
92
|
+
"Ruby #{Logger.name} path: #{@config.log_path}"
|
99
93
|
end
|
100
94
|
end
|
101
95
|
|
102
96
|
# A logger class that outputs the file.
|
103
97
|
class FileLogger < LoggerBase
|
104
|
-
|
98
|
+
@@log_path_default = 'debugtrace.log'
|
99
|
+
|
100
|
+
def initialize(config)
|
101
|
+
@log_path = @@log_path_default
|
105
102
|
@config = Common::check_type("config", config, Config)
|
106
|
-
Common::check_type("log_path", log_path, String)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
@
|
103
|
+
Common::check_type("log_path", config.log_path, String)
|
104
|
+
@log_path = config.log_path
|
105
|
+
@append = false
|
106
|
+
|
107
|
+
if @log_path.start_with?('+')
|
108
|
+
@log_path = @log_path[1..-1]
|
109
|
+
@append = true
|
110
|
+
end
|
111
|
+
|
112
|
+
dir_path = File.dirname(@log_path)
|
113
|
+
|
114
|
+
if !Dir.exist?(dir_path)
|
115
|
+
@log_path = @@log_path_default
|
116
|
+
@append = true
|
117
|
+
print("DebugTrace-rb: FileLogger: The directory '#{dir_path}' cannot be found.\n")
|
118
|
+
end
|
119
|
+
|
120
|
+
if !@append
|
121
|
+
File.open(@log_path, 'w') { |file|
|
122
|
+
}
|
113
123
|
end
|
114
124
|
end
|
115
125
|
|
116
126
|
def print(message)
|
117
|
-
|
118
|
-
if @log_path
|
119
|
-
File.open(@log_path, 'a') {|file|
|
127
|
+
# Common::check_type("message", message, String)
|
128
|
+
if File.exist?(@log_path)
|
129
|
+
File.open(@log_path, 'a') { |file|
|
120
130
|
datetime_str = Time.now().strftime(@config.logging_datetime_format)
|
121
131
|
file.puts "#{datetime_str} #{message}"
|
122
132
|
}
|
@@ -126,6 +136,6 @@ class FileLogger < LoggerBase
|
|
126
136
|
# Returns a string representation of this object.
|
127
137
|
# @return String: A string representation of this object
|
128
138
|
def to_s
|
129
|
-
"
|
139
|
+
"#{self.class.name} path: #{@log_path}, append: #{@append}"
|
130
140
|
end
|
131
141
|
end
|
data/lib/debugtrace/version.rb
CHANGED
data/lib/debugtrace.rb
CHANGED
@@ -47,29 +47,27 @@ module DebugTrace
|
|
47
47
|
@@logger = StdOutLogger.new(@@config)
|
48
48
|
when 'stderr'
|
49
49
|
@@logger = StdErrLogger.new(@@config)
|
50
|
-
when '
|
51
|
-
@@logger =
|
52
|
-
when
|
50
|
+
when 'rubylogger'
|
51
|
+
@@logger = RubyLogger.new(@@config)
|
52
|
+
when 'file'
|
53
53
|
@@logger = FileLogger.new(@@config)
|
54
54
|
else
|
55
|
-
|
55
|
+
@@logger = StdErrLogger.new(@@config)
|
56
|
+
@@logger.print("DebugTrace-rb: logger = #{@@config.logger_name} is unknown. (#{@@config.config_path}) \n")
|
56
57
|
end
|
57
58
|
|
58
59
|
return unless @@config.enabled?
|
59
60
|
|
60
|
-
|
61
|
-
@@logger.print("
|
62
|
-
@@logger.print(" config file path: #{@@config.config_path}")
|
61
|
+
@@logger.print("DebugTrace-rb #{DebugTrace::VERSION} on Ruby #{RUBY_VERSION}")
|
62
|
+
@@logger.print(" config file: #{@@config.config_path}")
|
63
63
|
@@logger.print(" logger: #{@@logger}")
|
64
64
|
end
|
65
65
|
|
66
66
|
class PrintOptions
|
67
|
-
attr_reader :
|
68
|
-
:minimum_output_count, :minimum_output_length,
|
67
|
+
attr_reader :minimum_output_count, :minimum_output_length,
|
69
68
|
:collection_limit, :bytes_limit, :string_limit, :reflection_limit
|
70
69
|
|
71
70
|
def initialize(
|
72
|
-
reflection,
|
73
71
|
minimum_output_count,
|
74
72
|
minimum_output_length,
|
75
73
|
collection_limit,
|
@@ -77,7 +75,6 @@ module DebugTrace
|
|
77
75
|
string_limit,
|
78
76
|
reflection_limit
|
79
77
|
)
|
80
|
-
@reflection = reflection
|
81
78
|
@minimum_output_count = minimum_output_count == -1 ? DebugTrace.config.minimum_output_count : minimum_output_count
|
82
79
|
@minimum_output_length = minimum_output_length == -1 ? DebugTrace.config.minimum_output_length : minimum_output_length
|
83
80
|
@collection_limit = collection_limit == -1 ? DebugTrace.config.collection_limit : collection_limit
|
@@ -133,27 +130,20 @@ module DebugTrace
|
|
133
130
|
value_buff = to_string_enumerable(value, print_options)
|
134
131
|
buff.append_buffer(separator, value_buff)
|
135
132
|
else
|
133
|
+
# use reflection
|
136
134
|
value_buff = LogBuffer.new(@@config.maximum_data_output_width)
|
137
|
-
if
|
138
|
-
#
|
139
|
-
value_buff.
|
140
|
-
|
141
|
-
|
135
|
+
if @@reflected_objects.any? { |obj| value.equal?(obj) }
|
136
|
+
# cyclic reference
|
137
|
+
value_buff.no_break_append(@@config.cyclic_reference_string)
|
138
|
+
elsif @@reflected_objects.length > print_options.reflection_limit
|
139
|
+
# over reflection level limitation
|
140
|
+
value_buff.no_break_append(@@config.limit_string)
|
142
141
|
else
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
value_buff.no_break_append(@@config.cyclic_reference_string)
|
147
|
-
elsif @@reflected_objects.length > print_options.reflection_limit
|
148
|
-
# over reflection level limitation
|
149
|
-
value_buff.no_break_append(@@config.limit_string)
|
150
|
-
else
|
151
|
-
@@reflected_objects.push(value)
|
152
|
-
value_buff = to_string_reflection(value, print_options)
|
153
|
-
@@reflected_objects.pop
|
154
|
-
end
|
155
|
-
buff.append_buffer(separator, value_buff)
|
142
|
+
@@reflected_objects.push(value)
|
143
|
+
value_buff = to_string_reflection(value, print_options)
|
144
|
+
@@reflected_objects.pop
|
156
145
|
end
|
146
|
+
buff.append_buffer(separator, value_buff)
|
157
147
|
end
|
158
148
|
|
159
149
|
buff
|
@@ -462,7 +452,7 @@ module DebugTrace
|
|
462
452
|
|
463
453
|
@@DO_NOT_OUTPUT = 'Do not output'
|
464
454
|
|
465
|
-
def self.print(name, value = @@DO_NOT_OUTPUT,
|
455
|
+
def self.print(name, value = @@DO_NOT_OUTPUT,
|
466
456
|
minimum_output_count: -1, minimum_output_length: -1,
|
467
457
|
collection_limit: -1, bytes_limit: -1,
|
468
458
|
string_limit: -1, reflection_limit: -1)
|
@@ -482,7 +472,6 @@ module DebugTrace
|
|
482
472
|
else
|
483
473
|
# with value
|
484
474
|
print_options = PrintOptions.new(
|
485
|
-
reflection,
|
486
475
|
minimum_output_count, minimum_output_length,
|
487
476
|
collection_limit, bytes_limit,
|
488
477
|
string_limit, reflection_limit
|