Class: LLM::Tracer::PrettyLogger
- Inherits:
-
Tracer
- Object
- Tracer
- LLM::Tracer::PrettyLogger
- Defined in:
- lib/llm/tracer/pretty_logger.rb
Overview
The LLM::Tracer::PrettyLogger class writes human-readable request and tool call logs to a console or file. Each event is a single line with the relevant context inline, no structured JSON.
Instance Method Summary collapse
-
#initialize(provider, options = {}) ⇒ PrettyLogger
constructor
A new instance of PrettyLogger.
- #on_request_error(ex:) ⇒ void
- #on_request_finish(operation:, res:, model: nil) ⇒ void
- #on_request_start(operation:, model: nil) ⇒ void
- #on_tool_error(ex:) ⇒ void
- #on_tool_finish(result:) ⇒ void
- #on_tool_start(id:, name:, arguments:) ⇒ void
Constructor Details
#initialize(provider, options = {}) ⇒ PrettyLogger
Returns a new instance of PrettyLogger.
19 20 21 22 |
# File 'lib/llm/tracer/pretty_logger.rb', line 19 def initialize(provider, = {}) super setup!(**) end |
Instance Method Details
#on_request_error(ex:) ⇒ void
This method returns an undefined value.
49 50 51 |
# File 'lib/llm/tracer/pretty_logger.rb', line 49 def on_request_error(ex:, **) @io.puts "#{} #{provider_name} error #{ex.class}: #{ex.}" end |
#on_request_finish(operation:, res:, model: nil) ⇒ void
This method returns an undefined value.
36 37 38 39 40 41 42 43 44 |
# File 'lib/llm/tracer/pretty_logger.rb', line 36 def on_request_finish(operation:, res:, model: nil, **) elapsed = @start ? (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @start).round(2) : nil tokens = format_tokens(res) name = operation == "chat" ? "chat" : operation parts = ["#{} #{provider_name} #{name} done"] parts << tokens if tokens parts << "#{elapsed}s" if elapsed @io.puts parts.join(", ") end |
#on_request_start(operation:, model: nil) ⇒ void
This method returns an undefined value.
27 28 29 30 31 |
# File 'lib/llm/tracer/pretty_logger.rb', line 27 def on_request_start(operation:, model: nil, **) @start = Process.clock_gettime(Process::CLOCK_MONOTONIC) name = operation == "chat" ? "chat" : operation @io.puts "#{} #{provider_name} #{name} (#{model || "default"})" end |
#on_tool_error(ex:) ⇒ void
This method returns an undefined value.
70 71 72 |
# File 'lib/llm/tracer/pretty_logger.rb', line 70 def on_tool_error(ex:, **) @io.puts "#{} tool error #{ex.class}: #{ex.}" end |
#on_tool_finish(result:) ⇒ void
This method returns an undefined value.
63 64 65 |
# File 'lib/llm/tracer/pretty_logger.rb', line 63 def on_tool_finish(result:, **) @io.puts "#{} #{result.name} -> #{format_value(result.value)}" end |
#on_tool_start(id:, name:, arguments:) ⇒ void
This method returns an undefined value.
56 57 58 |
# File 'lib/llm/tracer/pretty_logger.rb', line 56 def on_tool_start(id:, name:, arguments:, **) @io.puts "#{} #{name}(#{format_arguments(arguments)})" end |