Skip to content

feat(log_router): Append a string to truncated log messages#718

Open
Vincent-Dalstra wants to merge 2 commits into
espressif:masterfrom
Escape-This:dev
Open

feat(log_router): Append a string to truncated log messages#718
Vincent-Dalstra wants to merge 2 commits into
espressif:masterfrom
Escape-This:dev

Conversation

@Vincent-Dalstra
Copy link
Copy Markdown
Contributor

@Vincent-Dalstra Vincent-Dalstra commented May 15, 2026

Purpose

  1. Provide an easy visual indicator for when a log message was truncated in the log file.
  2. Ensure that each log message starts on a new line

Description

This feature detects when a log message is truncated due to it not fitting in the vprintf_buffer, and will append a string immediately after it so that someone reading the log file can see it occurred. A trailing newline character is also written, to make up for the one lost through truncation.

The string is formatted as purple italics to help distinguish the string from the actual log messages, unless CONFIG_LOG_COLORS is disabled.

The string may be set using a Kconfig option. An empty string means only the newline character will be printed. It can also be disabled completely.

Related

Testing

Manual testing, observing its behaviour is a large project. Files are written to fatfs emmc.

Tested all KConfig options as well

  • Default "<TRUNCATED>"
  • Empty string ""
  • Completely disabled - same behaviour as before.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@Vincent-Dalstra
Copy link
Copy Markdown
Contributor Author

Inspired by debugging related to: #717
and is based on the same commits, so it will need to be merged first.

@Vincent-Dalstra Vincent-Dalstra marked this pull request as ready for review May 15, 2026 07:45
The return value of vsnprintf() is used to determine how long the
message was. However, when vsprintf() truncates a message this value
will exceed the buffer! Then, vprintf_buffer[len] = '\0'; will cause
undefined behaviour.

Add a check for truncation, which resets 'len' to the number of bytes in
the buffer.

Also removed the -1 from the 'size' argument to vsnprintf(), because it
already accounts for the terminating '\0' byte.
Detect when a log message is truncated, and append a short string to
indicate this. The string is formatted as purple italics to distinguish
it from normal log messages. Also appends a newline character, so that
the next log message starts on its own line.

The string can be changed using menuconfig. An empty string will only
print a newline character. It can also be completely disabled.
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