diff mbox series

[U-Boot,4/9] log: Update log_console to honour the log format

Message ID 20171228201423.128338-5-sjg@chromium.org
State Accepted
Commit deca50fbd594d9aa845fc724a1758a1f61011ddb
Delegated to: Simon Glass
Headers show
Series log: Support control over the log output format | expand

Commit Message

Simon Glass Dec. 28, 2017, 8:14 p.m. UTC
At present this just outputs the message. Update it to output whatever the
format requests.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/log_console.c      | 27 ++++++++++++++++++++++++++-
 test/py/tests/test_log.py |  4 ++--
 2 files changed, 28 insertions(+), 3 deletions(-)

Comments

Simon Glass Jan. 26, 2018, 9:42 p.m. UTC | #1
On 28 December 2017 at 13:14, Simon Glass <sjg@chromium.org> wrote:
> At present this just outputs the message. Update it to output whatever the
> format requests.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  common/log_console.c      | 27 ++++++++++++++++++++++++++-
>  test/py/tests/test_log.py |  4 ++--
>  2 files changed, 28 insertions(+), 3 deletions(-)

Applied to u-boot-dm.
diff mbox series

Patch

diff --git a/common/log_console.c b/common/log_console.c
index 5af73bd8be..2902733078 100644
--- a/common/log_console.c
+++ b/common/log_console.c
@@ -10,9 +10,34 @@ 
 #include <common.h>
 #include <log.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
 {
-	puts(rec->msg);
+	int fmt = gd->log_fmt;
+
+	/*
+	 * The output format is designed to give someone a fighting chance of
+	 * figuring out which field is which:
+	 *    - level is in CAPS
+	 *    - cat is lower case and ends with comma
+	 *    - file normally has a .c extension and ends with a colon
+	 *    - line is integer and ends with a -
+	 *    - function is an identifier and ends with ()
+	 *    - message has a space before it unless it is on its own
+	 */
+	if (fmt & (1 << LOGF_LEVEL))
+		printf("%s.", log_get_level_name(rec->level));
+	if (fmt & (1 << LOGF_CAT))
+		printf("%s,", log_get_cat_name(rec->cat));
+	if (fmt & (1 << LOGF_FILE))
+		printf("%s:", rec->file);
+	if (fmt & (1 << LOGF_LINE))
+		printf("%d-", rec->line);
+	if (fmt & (1 << LOGF_FUNC))
+		printf("%s()", rec->func);
+	if (fmt & (1 << LOGF_MSG))
+		printf("%s%s", fmt != (1 << LOGF_MSG) ? " " : "", rec->msg);
 
 	return 0;
 }
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index fa9a25e8dc..517f415143 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -28,9 +28,9 @@  def test_log(u_boot_console):
         """
         for i in range(max_level):
             if mask & 1:
-                assert 'log %d' % i == lines.next()
+                assert 'log_run() log %d' % i == lines.next()
             if mask & 3:
-                assert '_log %d' % i == lines.next()
+                assert 'func() _log %d' % i == lines.next()
 
     def run_test(testnum):
         """Run a particular test number (the 'log test' command)