Skip to content

fix(layout): omit message separator space when payload is empty - #319

Open
tisonkun wants to merge 1 commit into
mainfrom
fix/text-empty-payload-space
Open

tisonkun wants to merge 1 commit into
mainfrom
fix/text-empty-payload-space

Conversation

@tisonkun

@tisonkun tisonkun commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

PlainTextLayout and TextLayout unconditionally wrote " {message}" before structured key-values and diagnostics. When Record::payload() formatted to an empty string (such as info!(logger, ["port" = 8080])), that left a trailing space when no fields followed or a double space before the first key=value pair.

This PR records the buffer offset before pushing the message separator space in both PlainTextLayout and TextLayout, and pops the separator byte if write!(writer, "{}", record.payload()) appended zero bytes, keeping empty-payload formatting allocation-free while preserving rollback on formatting errors.

Test Plan

  • Add empty-payload unit and macro tests (covering static and dynamic empty payloads, with and without key-values/diagnostics and metadata toggles) in tests-integration/tests/core_test/record_and_layout.rs and tests-integration/tests/layout_test/text.rs.

Avoid leaving an extra space in `PlainTextLayout` and `TextLayout` when `Record::payload()` produces zero bytes by popping the separator space from the output buffer when nothing was written for the message segment.

Signed-off-by: tison <wander4096@gmail.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