log: Handle line continuation

When multiple log() calls are used which don't end in newline, the
log prefix is prepended multiple times in the same line. This makes the
output look strange.

Fix this by detecting when the previous log record did not end in newline.
In that case, setting a flag.

Drop the unused BUFFSIZE in the test while we are here.

As an example implementation, update log_console to check the flag and
produce the expected output.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2021-03-12 17:41:35 -05:00
committed by Tom Rini
parent 79d5983b61
commit 9ad7a6c25c
6 changed files with 60 additions and 16 deletions
+16
View File
@@ -96,6 +96,22 @@ Also debug() and error() will generate log records - these use LOG_CATEGORY
as the category, so you should #define this right at the top of the source
file to ensure the category is correct.
Generally each log format_string ends with a newline. If it does not, then the
next log statement will have the LOGRECF_CONT flag set. This can be used to
continue the statement on the same line as the previous one without emitting
new header information (such as category/level). This behaviour is implemented
with log_console. Here is an example that prints a list all on one line with
the tags at the start:
.. code-block:: c
log_debug("Here is a list:");
for (i = 0; i < count; i++)
log_debug(" item %d", i);
log_debug("\n");
Also see the special category LOGL_CONT and level LOGC_CONT.
You can also define CONFIG_LOG_ERROR_RETURN to enable the log_ret() macro. This
can be used whenever your function returns an error value: