Class: LlmTranslate::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_translate/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Logger

Returns a new instance of Logger.



10
11
12
13
14
# File 'lib/llm_translate/logger.rb', line 10

def initialize(config)
  @config = config
  @logger = create_main_logger
  @error_logger = create_error_logger
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/llm_translate/logger.rb', line 8

def config
  @config
end

#error_loggerObject (readonly)

Returns the value of attribute error_logger.



8
9
10
# File 'lib/llm_translate/logger.rb', line 8

def error_logger
  @error_logger
end

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/llm_translate/logger.rb', line 8

def logger
  @logger
end

Instance Method Details

#debug(message) ⇒ Object



16
17
18
# File 'lib/llm_translate/logger.rb', line 16

def debug(message)
  logger.debug(format_message(message))
end

#error(message) ⇒ Object



28
29
30
31
# File 'lib/llm_translate/logger.rb', line 28

def error(message)
  logger.error(format_message(message))
  error_logger&.error(format_message(message))
end

#fatal(message) ⇒ Object



33
34
35
36
# File 'lib/llm_translate/logger.rb', line 33

def fatal(message)
  logger.fatal(format_message(message))
  error_logger&.fatal(format_message(message))
end

#info(message) ⇒ Object



20
21
22
# File 'lib/llm_translate/logger.rb', line 20

def info(message)
  logger.info(format_message(message))
end

#log_ai_request(prompt_length, model) ⇒ Object



50
51
52
53
54
# File 'lib/llm_translate/logger.rb', line 50

def log_ai_request(prompt_length, model)
  return unless config.verbose_translation?

  debug("AI Request - Model: #{model}, Prompt length: #{prompt_length} chars")
end

#log_ai_response(response_length, tokens_used = nil) ⇒ Object



56
57
58
59
60
61
# File 'lib/llm_translate/logger.rb', line 56

def log_ai_response(response_length, tokens_used = nil)
  return unless config.verbose_translation?

  token_info = tokens_used ? ", Tokens: #{tokens_used}" : ''
  debug("AI Response - Length: #{response_length} chars#{token_info}")
end

#log_translation_complete(file_path, output_path) ⇒ Object



44
45
46
47
48
# File 'lib/llm_translate/logger.rb', line 44

def log_translation_complete(file_path, output_path)
  return unless config.verbose_translation?

  info("Translation complete: #{file_path} -> #{output_path}")
end

#log_translation_start(file_path) ⇒ Object



38
39
40
41
42
# File 'lib/llm_translate/logger.rb', line 38

def log_translation_start(file_path)
  return unless config.verbose_translation?

  info("Starting translation: #{file_path}")
end

#warn(message) ⇒ Object



24
25
26
# File 'lib/llm_translate/logger.rb', line 24

def warn(message)
  logger.warn(format_message(message))
end