debugtrace 0.2.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5937a3c3f6b9d19ab3bb040ef763ada32e262c5046532331a7082f3edc3128cb
4
- data.tar.gz: 31b5c3027993f50d06409ec9c54d55adff5e68563a8f02b66ae6e618027ec550
3
+ metadata.gz: 573b6a776aab4ba5ffcd8b5f5b5c62c93250c9a637c11ee455325e79013b6243
4
+ data.tar.gz: 23f331e71a62a005ce75eb2e966fcafda2854d8ff73d42f6e399328df84deac1
5
5
  SHA512:
6
- metadata.gz: 33e2b5d74dcfcabfc0868652118694478e47ad5c6066e70c75090b50db7dc61008cfdfe5d4a9b438d7d7a2df91be97110d3766bfbbbd43536dfbaeacf0414c22
7
- data.tar.gz: bd78a8be204cd636d3104d06e3ff777ade2458f0492c5e50fd6f115f7108d290d4348cf02454721ca2680ef6a872455122b50e95fa836e8f9ed7efb1a17e7e6b
6
+ metadata.gz: 60707f1a062650f909b2a6f194a55edc0ad546823ea91f226b90b15dc943cd0157159bcde691ba5bae795fa3ad08698e5a6e6dfe139a6fbdd61087b74a1d06f2
7
+ data.tar.gz: 474b9c3cdfee32220b5bd182d14446c4762bd0e2d807dba3710ff797c653beb61087cffd2eb380fa3b9e28c8a6e0afcb87af82e28fed6caca78294bbc12f7b38
@@ -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 = _get_config_value 'logger' , 'stderr'
16
- @logging_destination = _get_config_value 'logging_destination' , 'STDERR'
17
- @logging_format = _get_config_value 'logging_format' , "%2$s %1$s %4$s\n"
18
- @logging_datetime_format = _get_config_value 'logging_datetime_format' , '%Y-%m-%d %H:%M:%S.%L%:z'
19
- @enabled = _get_config_value 'enabled' , true
20
- @enter_format = _get_config_value 'enter_format' , 'Enter %1$s (%2$s:%3$d) <- %4$s (%5$s:%6$d)'
21
- @leave_format = _get_config_value 'leave_format' , 'Leave %1$s (%2$s:%3$d) duration: %4$.3f ms'
22
- @thread_boundary_format = _get_config_value 'thread_boundary_format' , '______________________________ %1$s #%2$s ______________________________'
23
- @maximum_indents = _get_config_value 'maximum_indents' , 32
24
- @indent_string = _get_config_value 'indent_string' , '| '
25
- @data_indent_string = _get_config_value 'data_indent_string' , ' '
26
- @limit_string = _get_config_value 'limit_string' , '...'
27
- @non_output_string = _get_config_value 'non_output_string' , '...'
28
- @cyclic_reference_string = _get_config_value 'cyclic_reference_string' , '*** Cyclic Reference ***'
29
- @varname_value_separator = _get_config_value 'varname_value_separator' , ' = '
30
- @key_value_separator = _get_config_value 'key_value_separator' , ': '
31
- @print_suffix_format = _get_config_value 'print_suffix_format' , ' (%2$s:%3$d)'
32
- @count_format = _get_config_value 'count_format' , 'count:%d'
33
- @minimum_output_count = _get_config_value 'minimum_output_count' , 16
34
- @length_format = _get_config_value 'length_format' , 'length:%d'
35
- @minimum_output_length = _get_config_value 'minimum_output_length' , 16
36
- @maximum_data_output_width = _get_config_value 'maximum_data_output_width' , 70
37
- @bytes_count_in_line = _get_config_value 'bytes_count_in_line' , 16
38
- @collection_limit = _get_config_value 'collection_limit' , 128
39
- @bytes_limit = _get_config_value 'bytes_limit' , 256
40
- @string_limit = _get_config_value 'string_limit' , 256
41
- @reflection_limit = _get_config_value 'reflection_limit' , 4
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 _get_config_value(key, defalut_value)
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?
@@ -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 LoggerLogger
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.logging_destination,
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
- 'logging.Logger logger'
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
- def initialize(config, log_path)
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
- dir_path = File.dirname(log_path)
108
- if Dir.exist?(dir_path)
109
- @log_path = log_path
110
- else
111
- $stderr.puts "DebugTrace-rb: FileLogger: The directory '#{dir_path}' cannot be found."
112
- @log_path = ''
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
- Common::check_type("message", message, String)
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
- "File logger: '#{@log_path}"
139
+ "#{self.class.name} path: #{@log_path}, append: #{@append}"
130
140
  end
131
141
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DebugTrace
5
- VERSION = '0.2.2'
5
+ VERSION = '0.2.3'
6
6
  end
data/lib/debugtrace.rb CHANGED
@@ -47,19 +47,19 @@ module DebugTrace
47
47
  @@logger = StdOutLogger.new(@@config)
48
48
  when 'stderr'
49
49
  @@logger = StdErrLogger.new(@@config)
50
- when 'logger'
51
- @@logger = LoggerLogger.new(@@config)
52
- when /^file:/
50
+ when 'rubylogger'
51
+ @@logger = RubyLogger.new(@@config)
52
+ when 'file'
53
53
  @@logger = FileLogger.new(@@config)
54
54
  else
55
- Pr._print("debugtrace: (#{@@config.config_path}) logger = #{@@config.logger_name} is unknown", STDERR)
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
- ruby_version = RUBY_VERSION
61
- @@logger.print("DebugTrace-rb #{DebugTrace::VERSION} on Ruby #{ruby_version}")
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
 
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato Kokubo