debugtrace 0.2.3 → 0.2.4

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: ce8fe4113e5e6d49353414a4e204e96fd0bb18f303972a5e4aef48e0e7fa07d5
4
+ data.tar.gz: 0cdba9d53b9edbed09ef2ed76a76756abdc57fe5fbabd7ab886d06e3ab1d1623
5
5
  SHA512:
6
- metadata.gz: 60707f1a062650f909b2a6f194a55edc0ad546823ea91f226b90b15dc943cd0157159bcde691ba5bae795fa3ad08698e5a6e6dfe139a6fbdd61087b74a1d06f2
7
- data.tar.gz: 474b9c3cdfee32220b5bd182d14446c4762bd0e2d807dba3710ff797c653beb61087cffd2eb380fa3b9e28c8a6e0afcb87af82e28fed6caca78294bbc12f7b38
6
+ metadata.gz: cbdba0458650b624c0a7e6872c294f578e855fd3cb5d6e050ec4801a356a94fd29b3c3f5a00e01ef155860a8cde98e7b093c2f5f1b1cf5f0925c1904536e17d9
7
+ data.tar.gz: 34acc1fc0519aea58496c807f7716944696f596f2810d6403cee8c9e7b1184f29579420ab58cbe3a310d895e43ee9b351f90112c5d9154f71dfb5983075b58a1
@@ -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,8 +62,8 @@ 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
65
+ @size_format = get_value 'size_format' , 'size:%d'
66
+ @minimum_output_size = get_value 'minimum_output_size' , 16
63
67
  @length_format = get_value 'length_format' , 'length:%d'
64
68
  @minimum_output_length = get_value 'minimum_output_length' , 16
65
69
  @maximum_data_output_width = get_value 'maximum_data_output_width', 70
@@ -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.4'
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)
@@ -230,7 +237,7 @@ module DebugTrace
230
237
 
231
238
  if bytes_length >= @@config.minimum_output_length
232
239
  buff.no_break_append(' ')
233
- buff.no_break_append(format(@@config.length_format, bytes_length))
240
+ buff.no_break_append(format(@@config.size_format, bytes_length))
234
241
  end
235
242
 
236
243
  buff.no_break_append(') [')
@@ -414,9 +421,9 @@ module DebugTrace
414
421
  type_name = value.class.to_s
415
422
  type_name = '' if %w[Array Hash Set].include?(type_name)
416
423
 
417
- if count >= @@config.minimum_output_count
424
+ if count >= @@config.minimum_output_size
418
425
  type_name += ' ' unless type_name.empty?
419
- type_name += @@config.count_format % count
426
+ type_name += @@config.size_format % count
420
427
  end
421
428
 
422
429
  type_name
@@ -453,7 +460,7 @@ module DebugTrace
453
460
  @@DO_NOT_OUTPUT = 'Do not output'
454
461
 
455
462
  def self.print(name, value = @@DO_NOT_OUTPUT,
456
- minimum_output_count: -1, minimum_output_length: -1,
463
+ minimum_output_size: -1, minimum_output_length: -1,
457
464
  collection_limit: -1, bytes_limit: -1,
458
465
  string_limit: -1, reflection_limit: -1)
459
466
  @@thread_mutex.synchronize do
@@ -472,7 +479,7 @@ module DebugTrace
472
479
  else
473
480
  # with value
474
481
  print_options = PrintOptions.new(
475
- minimum_output_count, minimum_output_length,
482
+ minimum_output_size, minimum_output_length,
476
483
  collection_limit, bytes_limit,
477
484
  string_limit, reflection_limit
478
485
  )
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato Kokubo