Skip to content

do not overwrite fmt-dict message in FluentRecordFormatter - #213

Open
cpruijsen wants to merge 1 commit into
fluent:masterfrom
cpruijsen:fix/issue-190
Open

cpruijsen wants to merge 1 commit into
fluent:masterfrom
cpruijsen:fix/issue-190

Conversation

@cpruijsen

Copy link
Copy Markdown

FluentRecordFormatter no longer overwrites fmt-dict message with the unstructured fallback when the fmt dict already defines message. _structuring used to replace that field with the full log text after the fmt dict had already applied specifiers such as %(message).5s. Other fmt keys were not overwritten, which is why only message looked broken (#190). Dict and JSON-object merges still last-write-win.

Decision

Skip the fallback only when the fmt dict has a message key. The other options are to make _add_dic never overwrite existing keys, or to skip whenever data already has message. The README describes message as an additional key for string logs; changing _add_dic would change payload-wins-on-overlap for dict/JSON, and testing data would change exclude_attrs traceback melding. Can switch if format keys should always win.

Reporter expected "message":"mingl" in #190, from "%(message).5s" on "mingle: searching for neighbors". Stdlib % formatting produces that truncation; the fmt dict already did too, before the overwrite.

If a fmt dict contains "message": "%(message)s", message is now the stdlib LogRecord.message (no traceback). Use %(exc_text)s for the traceback, as in the issue's config. Omitting message from the fmt dict is unchanged and still includes traceback in the added message field.

Test plan

  • test_custom_fmt_truncates_message: reporter case; fails without the fix, passes with it
  • test_custom_fmt_truncates_non_string_message: log.info(42) with %(message).1s (same overwrite on the non-string branch)
  • tests/test_handler.py and tests/test_asynchandler.py still pass; full pytest tests 74 passed, 2 skipped
  • optional: confirm against a live Fluentd with the reporter's logging.config dict

Signed-off-by: Christopher Pruijsen <christopher.pruijsen@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