Class: Kotoshu::Debug::Logger
- Inherits:
-
Object
- Object
- Kotoshu::Debug::Logger
- Defined in:
- lib/kotoshu/debug_logger.rb
Overview
Debug logger for detailed spellchecking information.
Provides structured logging for lookup operations, suggestion generation, cache behavior, and decision trees.
Constant Summary collapse
- LEVELS =
Log levels
%i[info verbose trace].freeze
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#debug_cache(cache_type, key, hit:) ⇒ Object
Log cache operation.
-
#debug_decision_tree(word, decisions:) ⇒ Object
Log decision tree.
-
#debug_lookup(word, result:, time:) ⇒ Object
Log lookup operation.
-
#debug_suggestions(word, suggestions:, time:) ⇒ Object
Log suggestion generation.
-
#info(message) ⇒ Object
Log info message.
-
#initialize(output: $stderr, level: :info) ⇒ Logger
constructor
Create a new debug logger.
-
#trace(message) ⇒ Object
Log trace message.
-
#verbose(message) ⇒ Object
Log verbose message.
Constructor Details
#initialize(output: $stderr, level: :info) ⇒ Logger
Create a new debug logger.
19 20 21 22 23 |
# File 'lib/kotoshu/debug_logger.rb', line 19 def initialize(output: $stderr, level: :info) @output = output @level = level @indent = 0 end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
13 14 15 |
# File 'lib/kotoshu/debug_logger.rb', line 13 def level @level end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
13 14 15 |
# File 'lib/kotoshu/debug_logger.rb', line 13 def output @output end |
Instance Method Details
#debug_cache(cache_type, key, hit:) ⇒ Object
Log cache operation.
64 65 66 67 68 69 |
# File 'lib/kotoshu/debug_logger.rb', line 64 def debug_cache(cache_type, key, hit:) return unless should_log?(:trace) status = hit ? "HIT" : "MISS" output.puts "DEBUG: cache #{cache_type.upcase} #{status} \"#{key}\"" end |
#debug_decision_tree(word, decisions:) ⇒ Object
Log decision tree.
75 76 77 78 79 80 81 82 |
# File 'lib/kotoshu/debug_logger.rb', line 75 def debug_decision_tree(word, decisions:) return unless should_log?(:trace) output.puts "DEBUG: decision tree for \"#{word}\"" @indent += 2 print_decisions(decisions) @indent -= 2 end |
#debug_lookup(word, result:, time:) ⇒ Object
Log lookup operation.
30 31 32 33 34 35 |
# File 'lib/kotoshu/debug_logger.rb', line 30 def debug_lookup(word, result:, time:) return unless should_log?(:info) status = result ? "✓" : "✗" output.puts "DEBUG: lookup #{status} \"#{word}\" - #{time.round(3)}ms" end |
#debug_suggestions(word, suggestions:, time:) ⇒ Object
Log suggestion generation.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kotoshu/debug_logger.rb', line 42 def debug_suggestions(word, suggestions:, time:) return unless should_log?(:verbose) output.puts "DEBUG: suggestions for \"#{word}\" (#{time.round(3)}ms)" return unless should_log?(:trace) @indent += 2 suggestions.each do |suggestion| dist = suggestion.distance conf = suggestion.confidence source = suggestion.source output.puts "#{" " * @indent}#{suggestion.word} (dist: #{dist}, conf: #{conf.round(2)}, src: #{source})" end @indent -= 2 end |
#info(message) ⇒ Object
Log info message.
87 88 89 90 91 |
# File 'lib/kotoshu/debug_logger.rb', line 87 def info() return unless should_log?(:info) output.puts "DEBUG: #{}" end |
#trace(message) ⇒ Object
Log trace message.
105 106 107 108 109 |
# File 'lib/kotoshu/debug_logger.rb', line 105 def trace() return unless should_log?(:trace) output.puts "DEBUG: #{}" end |
#verbose(message) ⇒ Object
Log verbose message.
96 97 98 99 100 |
# File 'lib/kotoshu/debug_logger.rb', line 96 def verbose() return unless should_log?(:verbose) output.puts "DEBUG: #{}" end |