Body logging is tied to the logger's debug level, and streaming debug lines ignore the context logger

Open
#1,669 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@josh-sanders is already working on this.

Since Nov 15, 2026.

  • #1680 by @josh-sanders — open

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
ruby
Domain
backend, security

Research direction

Start in lib/ruby_llm/transport/connection.rb at the settings_for/logger block (around L207-251) to see how log_bodies is derived from logger.debug? and passed to the Faraday logger, then read lib/ruby_llm/protocol/streaming.rb and stream_accumulator.rb for the RubyLLM.logger.debug lines. Done means a config.log_bodies (and optionally log_errors) option defaulting to today's behaviour, streaming lines routed through @config.logger || RubyLLM.logger, and the error-chunk line gated on log_stream_debug. Wait for the maintainers to confirm the proposed option names before writing code, since the thread is still a design discussion.

Written by the indexing model from the issue text.

Description

bug

What happens

With config.logger = Rails.logger and the app running at debug (RAILS_LOG_LEVEL=debug, a common step when troubleshooting in production), RubyLLM logs every response body and every Faraday exception:

# lib/ruby_llm/transport/connection.rb (2.2.0)
logger = @config.logger || RubyLLM.logger   # L207
log_bodies: logger.debug?,                  # L219
faraday.response :logger, settings.logger,
                 bodies: settings.log_bodies,
                 errors: true,              # L251
                 log_level: :debug, ...

The only filters hide base64 data and embedding arrays. Gateways and OpenAI-compatible servers sometimes quote the request, headers or API key back in an error body. Those bodies go to the app log, and from there to any log sink, before the app's own error handling can scrub them.

At the moment the only way to keep the app at debug and still keep bodies out of the log is to wrap the logger so that debug? returns false.

Streaming uses the global logger

2.2.0 added a per-context config.logger, which the HTTP layer honours. The streaming code still writes to the global RubyLLM.logger, so a logger set on a context doesn't cover it:

# lib/ruby_llm/protocol/streaming.rb (2.2.0)
RubyLLM.logger.debug { "Stream completed: #{message.content}" }        # L76
RubyLLM.logger.debug { "Accumulating error chunk: #{chunk}" }          # L210, not gated by log_stream_debug

stream_accumulator.rb does the same (L30, L42, L150), but those lines are gated by log_stream_debug.

The error-chunk line logs a provider's raw error body at debug without checking log_stream_debug, unlike the other chunk-level lines.

Proposal

  1. Add a config.log_bodies option (default: the current behaviour, logger.debug?), so an app can stay at debug without logging request and response bodies. A log_errors option for Faraday's errors: true would cover exception messages the same way.
  2. In the streaming code, use the context's logger (@config.logger || RubyLLM.logger), as Transport::Connection#settings_for does.
  3. Gate "Accumulating error chunk" on log_stream_debug, like the other chunk-level lines.
  4. Optional: filter the context's configured API keys out of logged output. The Faraday logger already supports filter, so adding a filter for each non-empty *_api_key value in the context's configuration would cover the common case.

Happy to send a PR for 1–3 if this direction sounds right.

Versions

  • ruby_llm 2.1.1 and 2.2.0 (same body/exception logging; 2.2.0 adds the per-context logger)
  • Faraday 2.x
Dominant language
Ruby
Stars
4.5k
Forks
537
Avg merge
7h 30m
Merged PRs (30d)
378

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from crmne/ruby_llm

All issues in crmne/ruby_llm

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.