debugtrace 0.2.6 → 0.2.7
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/lib/debugtrace/common.rb +6 -5
- data/lib/debugtrace/config.rb +4 -2
- data/lib/debugtrace/log_buffer.rb +23 -11
- data/lib/debugtrace/loggers.rb +29 -12
- data/lib/debugtrace/state.rb +12 -6
- data/lib/debugtrace/version.rb +1 -1
- data/lib/debugtrace.rb +105 -35
- 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: 4ba0b48484b98dad04cefc154c88afc5e82e88d551ab00d81dd3ddbe323a0e7a
         | 
| 4 | 
            +
              data.tar.gz: 6f858f96393d92d0b13f4ec5f34877d9d48623990d0251cd8c6c0f81d6616c1c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 55d162f057c2686e1c350caac7c3b4a48f493d04b344711ea2beb8c5a995ff9066334c845fc58e0d6a82dee76d17cfe001f22a74f76d47841b8ad076877a6e61
         | 
| 7 | 
            +
              data.tar.gz: ce01d78482c3fa14a84f21b8d7b7f68a5ffe2efd3dee453d5ae622256818509b4ec7b9df037f121e8caaf032dfe84a10ee3ea205e4b2793877a222a3b7395c1e
         | 
    
        data/LICENSE
    CHANGED
    
    
    
        data/lib/debugtrace/common.rb
    CHANGED
    
    | @@ -2,16 +2,17 @@ | |
| 2 2 | 
             
            # (C) 2025 Masato Kokubo
         | 
| 3 3 |  | 
| 4 4 | 
             
            # Defines commonly used functions.
         | 
| 5 | 
            -
            # @author Masato Kokubo
         | 
| 6 5 | 
             
            module Common
         | 
| 7 6 | 
             
              # Check the value types.
         | 
| 7 | 
            +
              #
         | 
| 8 8 | 
             
              # @param value_name [String] the value name
         | 
| 9 9 | 
             
              # @param value [String] the value
         | 
| 10 10 | 
             
              # @param type [Class] the type
         | 
| 11 | 
            -
              # @ | 
| 11 | 
            +
              # @return [String] the value
         | 
| 12 | 
            +
              # @raise [TypeError] if the value is not an instance of the type or the subclass of the type
         | 
| 12 13 | 
             
              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)
         | 
| 14 | 
            +
                raise TypeError("Argument value_name (=#{value_name}) must be a String") unless value_name.is_a?(String)
         | 
| 15 | 
            +
                raise TypeError("Argument type (=#{type}) must be a Class") unless type.is_a?(Class)
         | 
| 15 16 |  | 
| 16 17 | 
             
                error = false
         | 
| 17 18 | 
             
                if type == FalseClass || type == TrueClass
         | 
| @@ -28,7 +29,7 @@ module Common | |
| 28 29 | 
             
                  top_type_name = type.name.slice(0).upcase
         | 
| 29 30 | 
             
                  a = top_type_name == 'A' || top_type_name == 'I' || top_type_name == 'U' ||
         | 
| 30 31 | 
             
                    top_type_name == 'E' || top_type_name == 'O' ? 'an' : 'a'
         | 
| 31 | 
            -
                  raise "Argument #{value_name} (=#{value_string}) must be #{a} #{type}"
         | 
| 32 | 
            +
                  raise TypeError("Argument #{value_name} (=#{value_string}) must be #{a} #{type}")
         | 
| 32 33 | 
             
                end
         | 
| 33 34 | 
             
                return value
         | 
| 34 35 | 
             
              end
         | 
    
        data/lib/debugtrace/config.rb
    CHANGED
    
    | @@ -4,7 +4,6 @@ require 'yaml' | |
| 4 4 | 
             
            require_relative 'common'
         | 
| 5 5 |  | 
| 6 6 | 
             
            # Retains the contents defined in debugtrace.yml.
         | 
| 7 | 
            -
            # @author Masato Kokubo
         | 
| 8 7 | 
             
            class Config
         | 
| 9 8 | 
             
              attr_reader :config_path
         | 
| 10 9 | 
             
              attr_reader :config
         | 
| @@ -36,6 +35,7 @@ class Config | |
| 36 35 | 
             
              attr_reader :reflection_limit
         | 
| 37 36 |  | 
| 38 37 | 
             
              # Initializes with a yml file in the config_path.
         | 
| 38 | 
            +
              #
         | 
| 39 39 | 
             
              # @param config_path [String] path of the yml file
         | 
| 40 40 | 
             
              def initialize(config_path)
         | 
| 41 41 | 
             
                @config_path = Common.check_type('config_path', config_path, String)
         | 
| @@ -75,7 +75,8 @@ class Config | |
| 75 75 | 
             
              end
         | 
| 76 76 |  | 
| 77 77 | 
             
              # Returns true if logging is enabled, false otherwise.
         | 
| 78 | 
            -
              # | 
| 78 | 
            +
              #
         | 
| 79 | 
            +
              # @return [TrueClass, FalseClass] true if logging is enabled, false otherwise
         | 
| 79 80 | 
             
              def enabled?
         | 
| 80 81 | 
             
                return @enabled
         | 
| 81 82 | 
             
              end
         | 
| @@ -83,6 +84,7 @@ class Config | |
| 83 84 | 
             
              private
         | 
| 84 85 |  | 
| 85 86 | 
             
              # Gets the value related the key from debugtrace.yml file.
         | 
| 87 | 
            +
              #
         | 
| 86 88 | 
             
              # @param key [String] the key
         | 
| 87 89 | 
             
              # @param defalut_value [Object] value to return if the value related the key is undefined
         | 
| 88 90 | 
             
              # @return [Object] value related the key
         | 
| @@ -3,17 +3,23 @@ | |
| 3 3 | 
             
            require_relative 'common'
         | 
| 4 4 |  | 
| 5 5 | 
             
            # Buffers logs.
         | 
| 6 | 
            -
            # @author Masato Kokubo
         | 
| 7 6 | 
             
            class LogBuffer
         | 
| 7 | 
            +
              # Contains a single line indentation level and log content.
         | 
| 8 8 | 
             
              class LevelAndLog
         | 
| 9 | 
            +
                attr_reader :nest_level, :log
         | 
| 10 | 
            +
             | 
| 9 11 | 
             
                # Initializes this object.
         | 
| 12 | 
            +
                #
         | 
| 13 | 
            +
                # @param nest_level [Integer] the nesting level
         | 
| 14 | 
            +
                # @param log [String] the log message
         | 
| 10 15 | 
             
                def initialize(nest_level, log)
         | 
| 11 16 | 
             
                  @nest_level = Common.check_type('nest_level', nest_level, Integer)
         | 
| 12 17 | 
             
                  @log = Common.check_type('log', log, String)
         | 
| 13 18 | 
             
                end
         | 
| 14 19 |  | 
| 15 | 
            -
                 | 
| 16 | 
            -
             | 
| 20 | 
            +
                # Returns a string representation of this object.
         | 
| 21 | 
            +
                #
         | 
| 22 | 
            +
                # @return [String] a string representation of this object.
         | 
| 17 23 | 
             
                def to_s
         | 
| 18 24 | 
             
                  return "(LogBuffer.LevelAndLog){nest_level: #{@nest_level}, log: \"#{@log}\"}"
         | 
| 19 25 | 
             
                end
         | 
| @@ -50,11 +56,12 @@ class LogBuffer | |
| 50 56 | 
             
              end
         | 
| 51 57 |  | 
| 52 58 | 
             
              # Appends a string representation of the value.
         | 
| 59 | 
            +
              #
         | 
| 53 60 | 
             
              # @param value [Object] The value to append
         | 
| 54 61 | 
             
              # @param nest_level (int, optional): The nest level of the value. Defaults to 0
         | 
| 55 62 | 
             
              # @param no_break (bool, optional): If true, does not break even if the maximum width is exceeded.
         | 
| 56 63 | 
             
              #         Defaults to false
         | 
| 57 | 
            -
              # @return LogBuffer | 
| 64 | 
            +
              # @return [LogBuffer] this object
         | 
| 58 65 | 
             
              def append(value, nest_level = 0, no_break = false)
         | 
| 59 66 | 
             
                Common.check_type('nest_level', nest_level, Integer)
         | 
| 60 67 | 
             
                Common.check_type('no_break', no_break, TrueClass)
         | 
| @@ -69,17 +76,18 @@ class LogBuffer | |
| 69 76 |  | 
| 70 77 | 
             
              # Appends a string representation of the value.
         | 
| 71 78 | 
             
              # Does not break even if the maximum width is exceeded.
         | 
| 79 | 
            +
              #
         | 
| 72 80 | 
             
              # @param value [Object] The value to append
         | 
| 73 | 
            -
              # @return LogBuffer | 
| 81 | 
            +
              # @return [LogBuffer] this object
         | 
| 74 82 | 
             
              def no_break_append(value)
         | 
| 75 83 | 
             
                return append(value, 0, true)
         | 
| 76 84 | 
             
              end
         | 
| 77 85 |  | 
| 78 86 | 
             
              # Appends lines of another LogBuffer.
         | 
| 79 | 
            -
              # | 
| 80 | 
            -
              # @param separator [String]  | 
| 81 | 
            -
              # @param buff  | 
| 82 | 
            -
              # @ | 
| 87 | 
            +
              #
         | 
| 88 | 
            +
              # @param separator [String] the separator string to append if not ''
         | 
| 89 | 
            +
              # @param buff [LogBuffer] another LogBuffer
         | 
| 90 | 
            +
              # @return [LogBuffer] this object
         | 
| 83 91 | 
             
              def append_buffer(separator, buff)
         | 
| 84 92 | 
             
                Common.check_type('separator', separator, String)
         | 
| 85 93 | 
             
                Common.check_type('buff', buff, LogBuffer)
         | 
| @@ -98,12 +106,16 @@ class LogBuffer | |
| 98 106 | 
             
                return @last_line.length
         | 
| 99 107 | 
             
              end
         | 
| 100 108 |  | 
| 101 | 
            -
              # true if multiple line, false otherwise.
         | 
| 109 | 
            +
              # Returns true if multiple line, false otherwise.
         | 
| 110 | 
            +
              #
         | 
| 111 | 
            +
              # @return [FalseClass, TrueClass] true if multiple line, false otherwise.
         | 
| 102 112 | 
             
              def multi_lines?
         | 
| 103 113 | 
             
                return @lines.length > 1 || @lines.length == 1 && length > 0
         | 
| 104 114 | 
             
              end
         | 
| 105 115 |  | 
| 106 | 
            -
              #  | 
| 116 | 
            +
              # Returns the LevelAndLog objects.
         | 
| 117 | 
            +
              #
         | 
| 118 | 
            +
              # @return [Array<LevelAndLog>] the LevelAndLog objects.
         | 
| 107 119 | 
             
              def lines
         | 
| 108 120 | 
             
                lines = @lines.dup
         | 
| 109 121 | 
             
                lines << LevelAndLog.new(@nest_level, @last_line) if length > 0
         | 
    
        data/lib/debugtrace/loggers.rb
    CHANGED
    
    | @@ -4,13 +4,13 @@ require 'logger' | |
| 4 4 | 
             
            require_relative 'common'
         | 
| 5 5 | 
             
            require_relative 'config'
         | 
| 6 6 |  | 
| 7 | 
            -
            #  | 
| 8 | 
            -
            # @author Masato Kokubo
         | 
| 7 | 
            +
            # @abstract Base class for logger classes.
         | 
| 9 8 | 
             
            class LoggerBase
         | 
| 10 | 
            -
              # Outputs the message.
         | 
| 9 | 
            +
              # @abstract Outputs the message.
         | 
| 11 10 | 
             
              # @param message [String] The message to output
         | 
| 11 | 
            +
              # @raise [Exception] always
         | 
| 12 12 | 
             
              def print(message)
         | 
| 13 | 
            -
                raise 'LoggerBase.print is an abstract method.'
         | 
| 13 | 
            +
                raise Exception.new('LoggerBase.print is an abstract method.')
         | 
| 14 14 | 
             
              end
         | 
| 15 15 |  | 
| 16 16 | 
             
              # Returns a string representation of this object.
         | 
| @@ -23,18 +23,19 @@ end | |
| 23 23 | 
             
            # Abstract base class for StdOut and StdErr classes.
         | 
| 24 24 | 
             
            class StdLogger < LoggerBase
         | 
| 25 25 | 
             
              # Initializes this object.
         | 
| 26 | 
            -
              # @param  | 
| 27 | 
            -
              def initialize(config,  | 
| 26 | 
            +
              # @param [IO] Output destination
         | 
| 27 | 
            +
              def initialize(config, output)
         | 
| 28 28 | 
             
                @config = Common::check_type("config", config, Config)
         | 
| 29 | 
            -
                @ | 
| 29 | 
            +
                @output = output
         | 
| 30 30 | 
             
              end
         | 
| 31 31 |  | 
| 32 32 | 
             
              # Outputs the message.
         | 
| 33 | 
            -
              # @param message [String]  | 
| 33 | 
            +
              # @param message [String] the message to output
         | 
| 34 | 
            +
              # @return [String] the message
         | 
| 34 35 | 
             
              def print(message)
         | 
| 35 36 | 
             
                Common::check_type("message", message, String)
         | 
| 36 37 | 
             
                datetime_str = Time.now().strftime(@config.logging_datetime_format)
         | 
| 37 | 
            -
                @ | 
| 38 | 
            +
                @output.puts "#{datetime_str} #{message}"
         | 
| 38 39 | 
             
              end
         | 
| 39 40 |  | 
| 40 41 | 
             
            end
         | 
| @@ -42,6 +43,7 @@ end | |
| 42 43 | 
             
            # A logger class that outputs to $stdout.
         | 
| 43 44 | 
             
            class StdOutLogger < StdLogger
         | 
| 44 45 | 
             
              # Initializes this object.
         | 
| 46 | 
            +
              # config [Config] a configuration object
         | 
| 45 47 | 
             
              def initialize(config)
         | 
| 46 48 | 
             
                super(config, $stdout)
         | 
| 47 49 | 
             
              end
         | 
| @@ -50,18 +52,21 @@ end | |
| 50 52 | 
             
            # A logger class that outputs to $stderr.
         | 
| 51 53 | 
             
            class StdErrLogger < StdLogger
         | 
| 52 54 | 
             
              # Initializes this object.
         | 
| 55 | 
            +
              # config [Config] a configuration object
         | 
| 53 56 | 
             
              def initialize(config)
         | 
| 54 57 | 
             
                super(config, $stderr)
         | 
| 55 58 | 
             
              end
         | 
| 56 59 | 
             
            end
         | 
| 57 60 |  | 
| 58 | 
            -
            # A logger class that outputs using  | 
| 61 | 
            +
            # A logger class that outputs using Ruby Logger.
         | 
| 59 62 | 
             
            class RubyLogger
         | 
| 60 63 | 
             
              private
         | 
| 61 64 |  | 
| 62 65 | 
             
              class Formatter
         | 
| 66 | 
            +
                # Initializes this object.
         | 
| 67 | 
            +
                # config [Config] a configuration object
         | 
| 63 68 | 
             
                def initialize(config)
         | 
| 64 | 
            -
                  @config = config
         | 
| 69 | 
            +
                  @config = Common::check_type("config", config, Config)
         | 
| 65 70 | 
             
                end
         | 
| 66 71 |  | 
| 67 72 | 
             
                def call(severity, datetime, progname, msg)
         | 
| @@ -72,6 +77,9 @@ class RubyLogger | |
| 72 77 |  | 
| 73 78 | 
             
              public
         | 
| 74 79 |  | 
| 80 | 
            +
              # Initializes this object.
         | 
| 81 | 
            +
              #
         | 
| 82 | 
            +
              # @param config [Config] a configuration object
         | 
| 75 83 | 
             
              def initialize(config)
         | 
| 76 84 | 
             
                @config = Common::check_type("config", config, Config)
         | 
| 77 85 | 
             
                @logger = Logger.new(
         | 
| @@ -81,6 +89,7 @@ class RubyLogger | |
| 81 89 | 
             
              end
         | 
| 82 90 |  | 
| 83 91 | 
             
              # Outputs the message.
         | 
| 92 | 
            +
              #
         | 
| 84 93 | 
             
              # @param message [String] The message to output
         | 
| 85 94 | 
             
              def print(message)
         | 
| 86 95 | 
             
                Common::check_type("message", message, String)
         | 
| @@ -89,6 +98,7 @@ class RubyLogger | |
| 89 98 | 
             
              end
         | 
| 90 99 |  | 
| 91 100 | 
             
              # Returns a string representation of this object.
         | 
| 101 | 
            +
              #
         | 
| 92 102 | 
             
              # @return [String] A string representation of this object
         | 
| 93 103 | 
             
              def to_s
         | 
| 94 104 | 
             
                return "Ruby #{Logger.name} path: #{@config.log_path}"
         | 
| @@ -99,6 +109,9 @@ end | |
| 99 109 | 
             
            class FileLogger < LoggerBase
         | 
| 100 110 | 
             
              @@log_path_default = 'debugtrace.log'
         | 
| 101 111 |  | 
| 112 | 
            +
              # Initializes this object.
         | 
| 113 | 
            +
              #
         | 
| 114 | 
            +
              # @parm config [Config] a configuration object
         | 
| 102 115 | 
             
              def initialize(config)
         | 
| 103 116 | 
             
                @log_path = @@log_path_default
         | 
| 104 117 | 
             
                @config = Common::check_type("config", config, Config)
         | 
| @@ -125,8 +138,11 @@ class FileLogger < LoggerBase | |
| 125 138 | 
             
                end
         | 
| 126 139 | 
             
              end
         | 
| 127 140 |  | 
| 141 | 
            +
              # Outputs the message.
         | 
| 142 | 
            +
              #
         | 
| 143 | 
            +
              # @param message [String] the message to output
         | 
| 144 | 
            +
              # @return [String] the message
         | 
| 128 145 | 
             
              def print(message)
         | 
| 129 | 
            -
              # Common::check_type("message", message, String)
         | 
| 130 146 | 
             
                if File.exist?(@log_path)
         | 
| 131 147 | 
             
                  File.open(@log_path, 'a') { |file|
         | 
| 132 148 | 
             
                    datetime_str = Time.now().strftime(@config.logging_datetime_format)
         | 
| @@ -137,6 +153,7 @@ class FileLogger < LoggerBase | |
| 137 153 | 
             
              end
         | 
| 138 154 |  | 
| 139 155 | 
             
              # Returns a string representation of this object.
         | 
| 156 | 
            +
              #
         | 
| 140 157 | 
             
              # @return [String] A string representation of this object
         | 
| 141 158 | 
             
              def to_s
         | 
| 142 159 | 
             
                return "#{self.class.name} path: #{@log_path}, append: #{@append}"
         | 
    
        data/lib/debugtrace/state.rb
    CHANGED
    
    | @@ -2,24 +2,30 @@ | |
| 2 2 | 
             
            # (C) 2025 Masato Kokubo
         | 
| 3 3 | 
             
            require_relative 'common'
         | 
| 4 4 |  | 
| 5 | 
            -
            #  | 
| 6 | 
            -
            # @author Masato Kokubo
         | 
| 5 | 
            +
            # Contains the trace state for a thread
         | 
| 7 6 | 
             
            class State
         | 
| 8 7 | 
             
              attr_reader :thread_id
         | 
| 9 8 | 
             
              attr_reader :nest_level
         | 
| 10 9 | 
             
              attr_reader :previous_nest_level
         | 
| 11 10 |  | 
| 11 | 
            +
              # Initializes this object.
         | 
| 12 | 
            +
              #
         | 
| 13 | 
            +
              # @param thread_id [Integer] the object id of the thread
         | 
| 12 14 | 
             
              def initialize(thread_id)
         | 
| 13 | 
            -
                @thread_id = thread_id
         | 
| 15 | 
            +
                @thread_id = Common.check_type('thread_id', thread_id, Integer)
         | 
| 14 16 | 
             
                reset()
         | 
| 15 17 | 
             
              end
         | 
| 16 18 |  | 
| 19 | 
            +
              # Resets this object
         | 
| 17 20 | 
             
              def reset
         | 
| 18 21 | 
             
                @nest_level = 0
         | 
| 19 22 | 
             
                @previous_nest_level = 0
         | 
| 20 23 | 
             
                @times = []
         | 
| 21 24 | 
             
              end
         | 
| 22 25 |  | 
| 26 | 
            +
              # Returns a string representation of this object.
         | 
| 27 | 
            +
              #
         | 
| 28 | 
            +
              # @return [String] A string representation of this object
         | 
| 23 29 | 
             
              def to_s()
         | 
| 24 30 | 
             
                  return "(State){thread_id: #{@thread_id}, nest_level: #{@nest_level}, previous_nest_level: #{@previous_nest_level}, times: #{@times}}"
         | 
| 25 31 | 
             
              end
         | 
| @@ -31,11 +37,11 @@ class State | |
| 31 37 | 
             
                      @times.push(Time.now)
         | 
| 32 38 | 
             
                  end
         | 
| 33 39 | 
             
                  @nest_level += 1
         | 
| 34 | 
            -
                  return nil
         | 
| 35 40 | 
             
              end
         | 
| 36 41 |  | 
| 37 | 
            -
              #Downs the nest level.
         | 
| 38 | 
            -
              # | 
| 42 | 
            +
              # Downs the nest level.
         | 
| 43 | 
            +
              #
         | 
| 44 | 
            +
              # @return [Float] The time when the corresponding up_nest method was invoked
         | 
| 39 45 | 
             
              def down_nest
         | 
| 40 46 | 
             
                  @previous_nest_level = @nest_level
         | 
| 41 47 | 
             
                  @nest_level -= 1
         | 
    
        data/lib/debugtrace/version.rb
    CHANGED
    
    
    
        data/lib/debugtrace.rb
    CHANGED
    
    | @@ -10,7 +10,7 @@ require_relative 'debugtrace/log_buffer' | |
| 10 10 | 
             
            require_relative 'debugtrace/loggers'
         | 
| 11 11 | 
             
            require_relative 'debugtrace/state'
         | 
| 12 12 |  | 
| 13 | 
            -
            #  | 
| 13 | 
            +
            # The main module of DebugTrace-rb.
         | 
| 14 14 | 
             
            module DebugTrace
         | 
| 15 15 | 
             
              # Configuration values
         | 
| 16 16 | 
             
              @@config = nil
         | 
| @@ -37,6 +37,9 @@ module DebugTrace | |
| 37 37 | 
             
              # The logger used by DebugTrace-py
         | 
| 38 38 | 
             
              @@logger = nil
         | 
| 39 39 |  | 
| 40 | 
            +
              # Initialize this class
         | 
| 41 | 
            +
              #
         | 
| 42 | 
            +
              # @option [String] config_path the path to the configuration file. ./debugtrace.yml if not specified.
         | 
| 40 43 | 
             
              def self.initialize(config_path = './debugtrace.yml')
         | 
| 41 44 | 
             
                @@config = Config.new(config_path)
         | 
| 42 45 |  | 
| @@ -65,11 +68,22 @@ module DebugTrace | |
| 65 68 | 
             
                @@logger.print("  logger: #{@@logger}")
         | 
| 66 69 | 
             
              end
         | 
| 67 70 |  | 
| 71 | 
            +
              # Contains options to pass to the print method.
         | 
| 68 72 | 
             
              class PrintOptions
         | 
| 69 | 
            -
                attr_reader :minimum_output_size, :minimum_output_length,
         | 
| 73 | 
            +
                attr_reader :reflection, :minimum_output_size, :minimum_output_length,
         | 
| 70 74 | 
             
                            :collection_limit, :bytes_limit, :string_limit, :reflection_limit
         | 
| 71 75 |  | 
| 76 | 
            +
                # Initializes this object.
         | 
| 77 | 
            +
                #
         | 
| 78 | 
            +
                # @param reflection [TrueClass, FalseClass] use reflection if true
         | 
| 79 | 
            +
                # @param minimum_output_size [Integer] the minimum value to output the number of elements for Array and Hash (overrides debugtarace.yml value)
         | 
| 80 | 
            +
                # @param minimum_output_length [Integer] the minimum value to output the length of String and byte array (overrides debugtarace.yml value)
         | 
| 81 | 
            +
                # @param collection_limit [Integer] Output limit of collection elements (overrides debugtarace.yml value)
         | 
| 82 | 
            +
                # @param bytes_limit [Integer] the limit value of elements for bytes and bytearray to output (overrides debugtarace.yml value)
         | 
| 83 | 
            +
                # @param string_limit [Integer] the limit value of characters for string to output (overrides debugtarace.yml value)
         | 
| 84 | 
            +
                # @param reflection_limit [Integer] reflection limits when using reflection (overrides debugtarace.yml value)
         | 
| 72 85 | 
             
                def initialize(
         | 
| 86 | 
            +
                  reflection,
         | 
| 73 87 | 
             
                  minimum_output_size,
         | 
| 74 88 | 
             
                  minimum_output_length,
         | 
| 75 89 | 
             
                  collection_limit,
         | 
| @@ -77,6 +91,7 @@ module DebugTrace | |
| 77 91 | 
             
                  string_limit,
         | 
| 78 92 | 
             
                  reflection_limit
         | 
| 79 93 | 
             
                )
         | 
| 94 | 
            +
                  @reflection = reflection
         | 
| 80 95 | 
             
                  @minimum_output_size = minimum_output_size == -1 ? DebugTrace.config.minimum_output_size : minimum_output_size
         | 
| 81 96 | 
             
                  @minimum_output_length = minimum_output_length == -1 ? DebugTrace.config.minimum_output_length : minimum_output_length
         | 
| 82 97 | 
             
                  @collection_limit = collection_limit == -1 ? DebugTrace.config.collection_limit : collection_limit
         | 
| @@ -86,6 +101,9 @@ module DebugTrace | |
| 86 101 | 
             
                end
         | 
| 87 102 | 
             
              end
         | 
| 88 103 |  | 
| 104 | 
            +
              # Returns the current state.
         | 
| 105 | 
            +
              #
         | 
| 106 | 
            +
              # @return [State] the current state
         | 
| 89 107 | 
             
              def self.current_state
         | 
| 90 108 | 
             
                thread_id = Thread.current.object_id
         | 
| 91 109 |  | 
| @@ -99,12 +117,22 @@ module DebugTrace | |
| 99 117 | 
             
                return state
         | 
| 100 118 | 
             
              end
         | 
| 101 119 |  | 
| 120 | 
            +
              # Returns the current indent string.
         | 
| 121 | 
            +
              #
         | 
| 122 | 
            +
              # @param nest_level [Integer] the code nesting level
         | 
| 123 | 
            +
              # @param data_nest_level [Integer] the data nesting level
         | 
| 124 | 
            +
              # @return [Sring] the current indent string
         | 
| 102 125 | 
             
              def self.get_indent_string(nest_level, data_nest_level)
         | 
| 103 126 | 
             
                indent_str = @@config.indent_string * [[0, nest_level].max, @@config.maximum_indents].min
         | 
| 104 127 | 
             
                data_indent_str = @@config.data_indent_string * [[0, data_nest_level].max, @@config.maximum_indents].min
         | 
| 105 128 | 
             
                return indent_str + data_indent_str
         | 
| 106 129 | 
             
              end
         | 
| 107 130 |  | 
| 131 | 
            +
              # Returns a string representation of the variable contents.
         | 
| 132 | 
            +
              #
         | 
| 133 | 
            +
              # @param name [String] the variable name
         | 
| 134 | 
            +
              # @param value [Object] the value
         | 
| 135 | 
            +
              # @param print_options [PrintOptions] the print options
         | 
| 108 136 | 
             
              def self.to_string(name, value, print_options)
         | 
| 109 137 | 
             
                buff = LogBuffer.new(@@config.maximum_data_output_width)
         | 
| 110 138 |  | 
| @@ -126,7 +154,8 @@ module DebugTrace | |
| 126 154 | 
             
                when Module
         | 
| 127 155 | 
             
                  buff.no_break_append(separator).append(value.name).no_break_append(' module')
         | 
| 128 156 | 
             
                when String
         | 
| 129 | 
            -
                  value_buff =  | 
| 157 | 
            +
                  value_buff = value.encoding == Encoding::ASCII_8BIT ?
         | 
| 158 | 
            +
                      to_string_bytes(value, print_options) : to_string_str(value, print_options)
         | 
| 130 159 | 
             
                  buff.append_buffer(separator, value_buff)
         | 
| 131 160 | 
             
                when DateTime
         | 
| 132 161 | 
             
                  buff.no_break_append(separator).append(value.strftime('%Y-%m-%d %H:%M-%S.%L%:z'))
         | 
| @@ -138,25 +167,33 @@ module DebugTrace | |
| 138 167 | 
             
                  value_buff = to_string_enumerable(value, print_options)
         | 
| 139 168 | 
             
                  buff.append_buffer(separator, value_buff)
         | 
| 140 169 | 
             
                else
         | 
| 141 | 
            -
                   | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
                     | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
                     | 
| 148 | 
            -
             | 
| 170 | 
            +
                  if print_options.reflection
         | 
| 171 | 
            +
                    # use reflection
         | 
| 172 | 
            +
                    value_buff = LogBuffer.new(@@config.maximum_data_output_width)
         | 
| 173 | 
            +
                    if @@reflected_objects.any? { |obj| value.equal?(obj) }
         | 
| 174 | 
            +
                      # cyclic reference
         | 
| 175 | 
            +
                      value_buff.no_break_append(@@config.cyclic_reference_string)
         | 
| 176 | 
            +
                    elsif @@reflected_objects.length > print_options.reflection_limit
         | 
| 177 | 
            +
                      # over reflection level limitation
         | 
| 178 | 
            +
                      value_buff.no_break_append(@@config.limit_string)
         | 
| 179 | 
            +
                    else
         | 
| 180 | 
            +
                      @@reflected_objects.push(value)
         | 
| 181 | 
            +
                      value_buff = to_string_reflection(value, print_options)
         | 
| 182 | 
            +
                      @@reflected_objects.pop
         | 
| 183 | 
            +
                    end
         | 
| 184 | 
            +
                    buff.append_buffer(separator, value_buff)
         | 
| 149 185 | 
             
                  else
         | 
| 150 | 
            -
                     | 
| 151 | 
            -
                    value_buff = to_string_reflection(value, print_options)
         | 
| 152 | 
            -
                    @@reflected_objects.pop
         | 
| 186 | 
            +
                    buff.no_break_append(separator).append(value.to_s)
         | 
| 153 187 | 
             
                  end
         | 
| 154 | 
            -
                  buff.append_buffer(separator, value_buff)
         | 
| 155 188 | 
             
                end
         | 
| 156 189 |  | 
| 157 190 | 
             
                return buff
         | 
| 158 191 | 
             
              end
         | 
| 159 192 |  | 
| 193 | 
            +
              # Returns a string representation of the string value
         | 
| 194 | 
            +
              #
         | 
| 195 | 
            +
              # @param value [String] the value
         | 
| 196 | 
            +
              # @param print_options [PrintOptions] the print options
         | 
| 160 197 | 
             
              def self.to_string_str(value, print_options)
         | 
| 161 198 | 
             
                has_single_quote = false
         | 
| 162 199 | 
             
                has_double_quote = false
         | 
| @@ -219,16 +256,13 @@ module DebugTrace | |
| 219 256 | 
             
                return has_single_quote && !has_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
         |