Class: OllamaChat::Utils::ExconLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_chat/utils/excon_logger.rb

Overview

A lightweight Logger adapter that routes Excon log messages through the OllamaChat logging system.

This allows Excon's debug output to be captured and formatted consistently with the rest of the application, avoiding direct writes to $stderr.

Examples:

logger = OllamaChat::Utils::ExconLogger.new(chat)
excon = Excon.new(url, logger:)

Constant Summary collapse

LOG_METHODS =

Standard Ruby Logger severity methods to intercept

%i[debug info warn error fatal unknown].freeze

Instance Method Summary collapse

Constructor Details

#initialize(chat) ⇒ ExconLogger

Creates a new ExconLogger instance.

Parameters:



17
18
19
# File 'lib/ollama_chat/utils/excon_logger.rb', line 17

def initialize(chat)
  @chat = chat
end

Instance Method Details

#<<(_message) ⇒ nil

Stub for Logger#<<(not used by Excon LoggingInstrumentor).

Parameters:

  • _message (String)

    the log message

Returns:

  • (nil)


40
41
42
# File 'lib/ollama_chat/utils/excon_logger.rb', line 40

def <<(_message)
  nil
end

#methodNilClass, TrueClass

Dynamically defines all standard logger severity methods to route through the chat's logging system.

Parameters:

  • message (String)

    the log message

Returns:

  • (NilClass, TrueClass)


26
27
28
29
30
31
32
33
34
# File 'lib/ollama_chat/utils/excon_logger.rb', line 26

LOG_METHODS.each do |method|
  define_method(method) do |message = nil, &block|
    msg = block&.(message) || message
    return unless msg

    @chat.log(:debug, "Excon", data: { method => msg })
    true
  end
end