debugtrace 0.2.3 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 573b6a776aab4ba5ffcd8b5f5b5c62c93250c9a637c11ee455325e79013b6243
4
- data.tar.gz: 23f331e71a62a005ce75eb2e966fcafda2854d8ff73d42f6e399328df84deac1
3
+ metadata.gz: 665b9852fb34caab345012ab6bac6e18c0e8951d689125ea9cf0c399a0c7637e
4
+ data.tar.gz: d0940c27f8beec19e0aecfc609ddab7a35ecefedcde6251b1de5382d9d8ea319
5
5
  SHA512:
6
- metadata.gz: 60707f1a062650f909b2a6f194a55edc0ad546823ea91f226b90b15dc943cd0157159bcde691ba5bae795fa3ad08698e5a6e6dfe139a6fbdd61087b74a1d06f2
7
- data.tar.gz: 474b9c3cdfee32220b5bd182d14446c4762bd0e2d807dba3710ff797c653beb61087cffd2eb380fa3b9e28c8a6e0afcb87af82e28fed6caca78294bbc12f7b38
6
+ metadata.gz: 3b3a87106db56eb5c88c42c28f5c25eaf17a19a502c82411853554200c7ddaa7c5117248d5b0059206a467b53a47abdf9e37a4aa4b736199f051b76cbe4ecd0d
7
+ data.tar.gz: db33d2a6c4df894006aa1daada1fa777cdb0908ffeb4ccdb9b5de95e86dbece0835d0bea23a39c7f185dcf3fa36b6304ad680a185f58598a8cbe74b6d6bcb328
@@ -1,22 +1,30 @@
1
1
  # common.rb
2
2
  # (C) 2025 Masato Kokubo
3
+
4
+ # Defines commonly used functions.
5
+ # @author Masato Kokubo
3
6
  module Common
7
+ # Check the value types.
8
+ # @param value_name [String] the value name
9
+ # @param value [String] the value
10
+ # @param type [Class] the type
11
+ # @raise if the value is not an instance of the type or the subclass of the type
4
12
  def self.check_type(value_name, value, type)
5
- if !(value_name.is_a? String); raise "Argument value_name (=#{value_name}) must be a String"; end
6
- if !(type.is_a? Class); raise "Argument type (=#{type}) must be a Class"; end
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)
7
15
 
8
16
  error = false
9
17
  if type == FalseClass || type == TrueClass
10
18
  # false or true
11
19
  if value.class != FalseClass && value.class != TrueClass
12
- check_error = true
20
+ error = true
13
21
  end
14
22
  else
15
- error = value.class != type
23
+ error = !value.is_a?(type)
16
24
  end
17
25
 
18
26
  if error
19
- value_string = value.class == String ? "\"#{value}\"" : "#{value}"
27
+ value_string = value.instance_of?(String) ? "\"#{value}\"" : "#{value}"
20
28
  top_type_name = type.name.slice(0).upcase
21
29
  a = top_type_name == 'A' || top_type_name == 'I' || top_type_name == 'U' ||
22
30
  top_type_name == 'E' || top_type_name == 'O' ? 'an' : 'a'
@@ -3,9 +3,11 @@
3
3
  require 'yaml'
4
4
  require_relative 'common'
5
5
 
6
+ # Retains the contents defined in debugtrace.yml.
7
+ # @author Masato Kokubo
6
8
  class Config
7
- attr_reader :config
8
9
  attr_reader :config_path
10
+ attr_reader :config
9
11
  attr_reader :logger_name
10
12
  attr_reader :log_path
11
13
  attr_reader :logging_format
@@ -22,8 +24,8 @@ class Config
22
24
  attr_reader :varname_value_separator
23
25
  attr_reader :key_value_separator
24
26
  attr_reader :print_suffix_format
25
- attr_reader :count_format
26
- attr_reader :minimum_output_count
27
+ attr_reader :size_format
28
+ attr_reader :minimum_output_size
27
29
  attr_reader :length_format
28
30
  attr_reader :minimum_output_length
29
31
  attr_reader :maximum_data_output_width
@@ -33,6 +35,8 @@ class Config
33
35
  attr_reader :string_limit
34
36
  attr_reader :reflection_limit
35
37
 
38
+ # Initializes with a yml file in the config_path.
39
+ # @param config_path [String] path of the yml file
36
40
  def initialize(config_path)
37
41
  @config_path = Common.check_type('config_path', config_path, String)
38
42
  if File.exist?(@config_path)
@@ -58,10 +62,10 @@ class Config
58
62
  @varname_value_separator = get_value 'varname_value_separator' , ' = '
59
63
  @key_value_separator = get_value 'key_value_separator' , ': '
60
64
  @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
+ @size_format = get_value 'size_format' , '(size:%d)'
66
+ @minimum_output_size = get_value 'minimum_output_size' , 256
67
+ @length_format = get_value 'length_format' , '(length:%d)'
68
+ @minimum_output_length = get_value 'minimum_output_length' , 256
65
69
  @maximum_data_output_width = get_value 'maximum_data_output_width', 70
66
70
  @bytes_count_in_line = get_value 'bytes_count_in_line' , 16
67
71
  @collection_limit = get_value 'collection_limit' , 128
@@ -70,14 +74,18 @@ class Config
70
74
  @reflection_limit = get_value 'reflection_limit' , 4
71
75
  end
72
76
 
73
- def enabled? = @enabled
77
+ # Returns true if logging is enabled, false otherwise.
78
+ # @return true if logging is enabled, false otherwise
79
+ def enabled?
80
+ @enabled
81
+ end
74
82
 
75
83
  private
76
84
 
77
- # Gets the value related the key from debugtrace.ini file.
78
- # @param key (String): The key
79
- # @param defalut_value (Object): Value to return when the value related the key is undefined
80
- # @return Object: Value related the key
85
+ # Gets the value related the key from debugtrace.yml file.
86
+ # @param key [String] the key
87
+ # @param defalut_value [Object] value to return if the value related the key is undefined
88
+ # @return [Object] value related the key
81
89
  def get_value(key, defalut_value)
82
90
  Common.check_type('key', key, String)
83
91
  value = defalut_value
@@ -3,6 +3,7 @@
3
3
  require_relative 'common'
4
4
 
5
5
  # Buffers logs.
6
+ # @author Masato Kokubo
6
7
  class LogBuffer
7
8
  class LevelAndLog
8
9
  # Initializes this object.
@@ -49,7 +50,7 @@ class LogBuffer
49
50
  end
50
51
 
51
52
  # Appends a string representation of the value.
52
- # @param value (Object): The value to append
53
+ # @param value [Object] The value to append
53
54
  # @param nest_level (int, optional): The nest level of the value. Defaults to 0
54
55
  # @param no_break (bool, optional): If true, does not break even if the maximum width is exceeded.
55
56
  # Defaults to false
@@ -68,7 +69,7 @@ class LogBuffer
68
69
 
69
70
  # Appends a string representation of the value.
70
71
  # Does not break even if the maximum width is exceeded.
71
- # @param value (Object): The value to append
72
+ # @param value [Object] The value to append
72
73
  # @return LogBuffer: This object
73
74
  def no_break_append(value)
74
75
  append(value, 0, true)
@@ -76,7 +77,7 @@ class LogBuffer
76
77
 
77
78
  # Appends lines of another LogBuffer.
78
79
  # @param
79
- # @param separator (String): The separator string to append if not ''
80
+ # @param separator [String] The separator string to append if not ''
80
81
  # @param buff (LogBuffer): Another LogBuffer
81
82
  # @returns LogBuffer: This object
82
83
  def append_buffer(separator, buff)
@@ -5,15 +5,16 @@ require_relative 'common'
5
5
  require_relative 'config'
6
6
 
7
7
  # Abstract base class for logger classes.
8
+ # @author Masato Kokubo
8
9
  class LoggerBase
9
10
  # Outputs the message.
10
- # @param message (String): The message to output
11
+ # @param message [String] The message to output
11
12
  def print(message)
12
13
  raise 'LoggerBase.print is an abstract method.'
13
14
  end
14
15
 
15
16
  # Returns a string representation of this object.
16
- # @return String: A string representation of this object
17
+ # @return [String] A string representation of this object
17
18
  def to_s
18
19
  "#{self.class.name}"
19
20
  end
@@ -29,7 +30,7 @@ class StdLogger < LoggerBase
29
30
  end
30
31
 
31
32
  # Outputs the message.
32
- # @param message (String): The message to output
33
+ # @param message [String] The message to output
33
34
  def print(message)
34
35
  Common::check_type("message", message, String)
35
36
  datetime_str = Time.now().strftime(@config.logging_datetime_format)
@@ -80,14 +81,14 @@ class RubyLogger
80
81
  end
81
82
 
82
83
  # Outputs the message.
83
- # @param message (String): The message to output
84
+ # @param message [String] The message to output
84
85
  def print(message)
85
86
  Common::check_type("message", message, String)
86
87
  @logger.log(Logger::Severity::DEBUG, message, 'DebugTrace-rb')
87
88
  end
88
89
 
89
90
  # Returns a string representation of this object.
90
- # @return String: A string representation of this object
91
+ # @return [String] A string representation of this object
91
92
  def to_s
92
93
  "Ruby #{Logger.name} path: #{@config.log_path}"
93
94
  end
@@ -134,7 +135,7 @@ class FileLogger < LoggerBase
134
135
  end
135
136
 
136
137
  # Returns a string representation of this object.
137
- # @return String: A string representation of this object
138
+ # @return [String] A string representation of this object
138
139
  def to_s
139
140
  "#{self.class.name} path: #{@log_path}, append: #{@append}"
140
141
  end
@@ -3,6 +3,7 @@
3
3
  require_relative 'common'
4
4
 
5
5
  # Have the trace state for a thread
6
+ # @author Masato Kokubo
6
7
  class State
7
8
  def initialize(thread_id)
8
9
  @thread_id = Common::check_type('thread_id', thread_id, Integer)
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DebugTrace
5
- VERSION = '0.2.3'
5
+ VERSION = '0.2.5'
6
6
  end
data/lib/debugtrace.rb CHANGED
@@ -10,6 +10,7 @@ require_relative 'debugtrace/log_buffer'
10
10
  require_relative 'debugtrace/loggers'
11
11
  require_relative 'debugtrace/state'
12
12
 
13
+ # @author Masato Kokubo
13
14
  module DebugTrace
14
15
  # Configuration values
15
16
  @@config = nil
@@ -64,18 +65,18 @@ module DebugTrace
64
65
  end
65
66
 
66
67
  class PrintOptions
67
- attr_reader :minimum_output_count, :minimum_output_length,
68
+ attr_reader :minimum_output_size, :minimum_output_length,
68
69
  :collection_limit, :bytes_limit, :string_limit, :reflection_limit
69
70
 
70
71
  def initialize(
71
- minimum_output_count,
72
+ minimum_output_size,
72
73
  minimum_output_length,
73
74
  collection_limit,
74
75
  bytes_limit,
75
76
  string_limit,
76
77
  reflection_limit
77
78
  )
78
- @minimum_output_count = minimum_output_count == -1 ? DebugTrace.config.minimum_output_count : minimum_output_count
79
+ @minimum_output_size = minimum_output_size == -1 ? DebugTrace.config.minimum_output_size : minimum_output_size
79
80
  @minimum_output_length = minimum_output_length == -1 ? DebugTrace.config.minimum_output_length : minimum_output_length
80
81
  @collection_limit = collection_limit == -1 ? DebugTrace.config.collection_limit : collection_limit
81
82
  @bytes_limit = bytes_limit == -1 ? DebugTrace.config.bytes_limit : bytes_limit
@@ -117,6 +118,12 @@ module DebugTrace
117
118
  buff.no_break_append(separator).append('nil')
118
119
  when FalseClass, TrueClass, Integer, Float
119
120
  buff.no_break_append(separator).append(value.to_s)
121
+ when Symbol
122
+ buff.no_break_append(separator).append(':').no_break_append(value.name)
123
+ when Class
124
+ buff.no_break_append(separator).append(value.name).no_break_append(' class')
125
+ when Module
126
+ buff.no_break_append(separator).append(value.name).no_break_append(' module')
120
127
  when String
121
128
  value_buff = to_string_str(value, print_options)
122
129
  buff.append_buffer(separator, value_buff)
@@ -156,12 +163,8 @@ module DebugTrace
156
163
  double_quote_buff = LogBuffer.new(@@config.maximum_data_output_width)
157
164
 
158
165
  if value.length >= @@config.minimum_output_length
159
- single_quote_buff.no_break_append('(')
160
166
  single_quote_buff.no_break_append(format(@@config.length_format, value.length))
161
- single_quote_buff.no_break_append(')')
162
- double_quote_buff.no_break_append('(')
163
167
  double_quote_buff.no_break_append(format(@@config.length_format, value.length))
164
- double_quote_buff.no_break_append(')')
165
168
  end
166
169
 
167
170
  single_quote_buff.no_break_append("'")
@@ -229,11 +232,10 @@ module DebugTrace
229
232
  end
230
233
 
231
234
  if bytes_length >= @@config.minimum_output_length
232
- buff.no_break_append(' ')
233
- buff.no_break_append(format(@@config.length_format, bytes_length))
235
+ buff.no_break_append(format(@@config.size_format, bytes_length))
234
236
  end
235
237
 
236
- buff.no_break_append(') [')
238
+ buff.no_break_append('[')
237
239
 
238
240
  multi_lines = bytes_length >= @@config.bytes_count_in_line
239
241
 
@@ -414,9 +416,8 @@ module DebugTrace
414
416
  type_name = value.class.to_s
415
417
  type_name = '' if %w[Array Hash Set].include?(type_name)
416
418
 
417
- if count >= @@config.minimum_output_count
418
- type_name += ' ' unless type_name.empty?
419
- type_name += @@config.count_format % count
419
+ if count >= @@config.minimum_output_size
420
+ type_name += @@config.size_format % count
420
421
  end
421
422
 
422
423
  type_name
@@ -453,7 +454,7 @@ module DebugTrace
453
454
  @@DO_NOT_OUTPUT = 'Do not output'
454
455
 
455
456
  def self.print(name, value = @@DO_NOT_OUTPUT,
456
- minimum_output_count: -1, minimum_output_length: -1,
457
+ minimum_output_size: -1, minimum_output_length: -1,
457
458
  collection_limit: -1, bytes_limit: -1,
458
459
  string_limit: -1, reflection_limit: -1)
459
460
  @@thread_mutex.synchronize do
@@ -472,7 +473,7 @@ module DebugTrace
472
473
  else
473
474
  # with value
474
475
  print_options = PrintOptions.new(
475
- minimum_output_count, minimum_output_length,
476
+ minimum_output_size, minimum_output_length,
476
477
  collection_limit, bytes_limit,
477
478
  string_limit, reflection_limit
478
479
  )
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.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato Kokubo