feat(log_router): Append a string to truncated log messages#718
Open
Vincent-Dalstra wants to merge 2 commits into
Open
feat(log_router): Append a string to truncated log messages#718Vincent-Dalstra wants to merge 2 commits into
Vincent-Dalstra wants to merge 2 commits into
Conversation
Contributor
Author
|
Inspired by debugging related to: #717 |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
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_COLORSis 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
Checklist
Before submitting a Pull Request, please ensure the following: