Module: OllamaChat::Logging

Included in:
Chat
Defined in:
lib/ollama_chat/logging.rb

Overview

Provides a simple logging facility for the OllamaChat application. It offers methods to access a logger, determine the current log level, and write messages at various severity levels, including debug.

Instance Method Summary collapse

Instance Method Details

#log(severity, msg, warn: false) ⇒ Object

The log method records a message or exception at the specified severity level using the logger and optionally triggers a warning output

Parameters:

  • severity (Symbol)

    the logging level to use

  • msg (String, Exception)

    the message or exception to be logged

  • warn (TrueClass, FalseClass) (defaults to: false)

    whether to also trigger a warning output



21
22
23
24
25
26
27
28
# File 'lib/ollama_chat/logging.rb', line 21

def log(severity, msg, warn: false)
  if msg.is_a?(Exception)
    msg = "Caught #{msg.class}: #{msg}\n#{Array(msg&.backtrace).join(?\n)}"
  end
  logger.send(severity, msg)
  warn and self.warn(msg)
  nil
end

#loggerLogger

The logger method returns the current Logger instance used by OllamaChat. If no Logger exists, it creates one pointing to the configured log file.

Returns:

  • (Logger)

    the active Logger instance



9
10
11
12
13
# File 'lib/ollama_chat/logging.rb', line 9

def logger
  @logger and return @logger
  OC::OLLAMA::CHAT::LOGFILE.dirname.mkpath
  @logger = Logger.new(OC::OLLAMA::CHAT::LOGFILE)
end