Skip to content

Log unknown severities and String or nil tags instead of raising - #51

Merged
PetrHeinz merged 2 commits into
mainfrom
claude/logger-api-crashes
Oct 2, 2026
Merged

PetrHeinz merged 2 commits into
mainfrom
claude/logger-api-crashes

Conversation

@PetrHeinz

Copy link
Copy Markdown
Member

logger.unknown("x"), logger.add(nil, "x") and logger.add(99, "x") raise KeyError: key not found: "ANY" from inside the formatter, so a call meant to log something crashes the caller instead. Ruby's Logger labels UNKNOWN, a nil severity and anything above it "ANY", and Formatter::SEVERITY_MAP only knows "UNKNOWN". A user field tags: holding a String or nil raises TypeError from Array#concat the same way. The red-team probe against 0.1.20 printed unknown: KeyError: key not found: "ANY" for all three severity calls.

  • SEVERITY_MAP maps "ANY" to :unknown, and a label it doesn't know falls back to :unknown instead of raising, just as Ruby's Logger#format_severity falls back to "ANY".
  • tag: and tags: go through Array(...), so a single String becomes a one-element list, and nil tags are skipped.

Behaviour and compatibility:

  • The calls above now log a line with level unknown, or with the given tags. Documented calls are unchanged.
  • tag: nil and nils inside a tags: array used to be sent as null tags. They are now left out.
  • tag: holding an Array is now flattened into the tags instead of being nested as a single element.

Targets the logtail 0.1.21 patch release. No dependencies on the other open PRs.

The first commit only adds the tests and is expected to fail on CI; the fix follows in the next commit.

🤖 Generated with Claude Code

PetrHeinz and others added 2 commits October 1, 2026 18:34
…/nil tags

logger.unknown, add(nil, ...) and add(99, ...) raise KeyError "ANY", and a
tags: field holding a String or nil raises TypeError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ruby's Logger formats UNKNOWN, nil and out-of-range severities as "ANY",
which the formatter's SEVERITY_MAP didn't know. Map it to :unknown, and fall
back to :unknown for any other label. Wrap tag: and tags: in Array() and skip
nil tags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PetrHeinz
PetrHeinz marked this pull request as ready for review October 2, 2026 09:04
@PetrHeinz
PetrHeinz merged commit dbb0f95 into main Oct 2, 2026
12 checks passed
@PetrHeinz
PetrHeinz deleted the claude/logger-api-crashes branch October 2, 2026 11:34
PetrHeinz added a commit that referenced this pull request Oct 2, 2026
Conflict in spec/logtail/logger_spec.rb: #51's describe "#unknown" and this
branch's describe "#flush" were added at the same place. Both are kept,
#unknown first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant