Body logging is tied to the logger's debug level, and streaming debug lines ignore the context logger
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 55/100
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
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
- Add a
config.log_bodiesoption (default: the current behaviour,logger.debug?), so an app can stay at debug without logging request and response bodies. Alog_errorsoption for Faraday'serrors: truewould cover exception messages the same way. - In the streaming code, use the context's logger (
@config.logger || RubyLLM.logger), asTransport::Connection#settings_fordoes. - Gate
"Accumulating error chunk"onlog_stream_debug, like the other chunk-level lines. - 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_keyvalue 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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from crmne/ruby_llm
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
crmne/ruby_llm#1682 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 22/100
crmne/ruby_llm#1674 · 1 comment ·
Maintainers usually reply within 1 day
-
[BUG] FileStore::Directory follows links to folders inside its own folderPossibly taken @yorzi claimed this 1 day ago. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 30/100
crmne/ruby_llm#1673 · 1 comment ·
Maintainers usually reply within 1 day
-
[BUG] FileStore::Directory#list returns nothing when a file vanishes mid-listingPossibly taken @yorzi claimed this 1 day ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 32/100
Maintainers usually reply within 1 day
Similar issues
-
Bug Ruby
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-ruby#3211 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
internetee/registry#2984 ·
Maintainers usually reply within 6 days
-
interest-zsv
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
hitobito/hitobito_zsv#6 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ecosyste-ms/issues#862 ·
Maintainers usually reply within 1 day
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredPossibly taken @mimosa claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day