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
-
#on_exit ⇒ nil
No-op.
- #on_request_start(operation:, model: nil)
- #on_request_finish(operation:, res:, model: nil)
- #on_request_error(ex:)
-
#on_tool_start(id:, name:, arguments:) ⇒ LLM::Object
The span an ending is handed, with the call's id and name.
- #on_tool_finish(result:)
- #on_tool_error(ex:)
- #on_tool_interrupt(ex:, span:)
- #on_interrupt(scope:)
-
#initialize(llm, options = {}) ⇒ PrettyLogger
constructor
A new instance of PrettyLogger.
Constructor Details
#initialize(llm, options = {}) ⇒ PrettyLogger
Returns a new instance of PrettyLogger.
19 20 21 22 |
# File 'lib/llm/tracer/pretty_logger.rb', line 19 def initialize(llm, = {}) super setup!(**) end |
Instance Method Details
#on_exit ⇒ nil
No-op.
93 94 95 |
# File 'lib/llm/tracer/pretty_logger.rb', line 93 def on_exit nil end |
#on_request_start(operation:, model: nil)
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 "#{} #{llm.name} #{name} (#{model || "default"})" end |
#on_request_finish(operation:, res:, model: nil)
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 = ["#{} #{llm.name} #{name} done"] parts << tokens if tokens parts << "#{elapsed}s" if elapsed @io.puts parts.join(", ") end |
#on_request_error(ex:)
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 "#{} #{llm.name} error #{ex.class}: #{ex.}" end |
#on_tool_start(id:, name:, arguments:) ⇒ LLM::Object
Returns The span an ending is handed, with the call's id and name.
57 58 59 60 |
# File 'lib/llm/tracer/pretty_logger.rb', line 57 def on_tool_start(id:, name:, arguments:, **) @io.puts "#{} #{name}(#{format_arguments(arguments)})" LLM::Object.from(id:, name:) end |
#on_tool_finish(result:)
This method returns an undefined value.
65 66 67 |
# File 'lib/llm/tracer/pretty_logger.rb', line 65 def on_tool_finish(result:, **) @io.puts "#{} #{result.name} -> #{format_value(result.value)}" end |
#on_tool_error(ex:)
This method returns an undefined value.
72 73 74 |
# File 'lib/llm/tracer/pretty_logger.rb', line 72 def on_tool_error(ex:, **) @io.puts "#{} tool error #{ex.value[:type]}: #{ex.value[:message]}" end |
#on_tool_interrupt(ex:, span:)
This method returns an undefined value.
79 80 81 |
# File 'lib/llm/tracer/pretty_logger.rb', line 79 def on_tool_interrupt(ex:, span:, **) @io.puts "#{} tool #{span.name} (#{format_id(span.id)}) received an interrupt" end |
#on_interrupt(scope:)
This method returns an undefined value.
86 87 88 |
# File 'lib/llm/tracer/pretty_logger.rb', line 86 def on_interrupt(scope:, **) @io.puts "#{} #{llm.name} interrupt received (scope=#{scope})" end |