public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 01/15] log: Add helpers for common log levels
Date: Mon,  1 Oct 2018 11:55:06 -0600	[thread overview]
Message-ID: <20181001175520.239554-2-sjg@chromium.org> (raw)
In-Reply-To: <20181001175520.239554-1-sjg@chromium.org>

At present to output a log message you need something like:

   log(UCLASS_SPI, LOCL_INFO, "message1");
   log(UCLASS_SPI, LOCL_INFO, "message2");

but many files use the same category throughout. Also it is helpful to
shorten the length of log names, providing helpers for common logging
levels. Add some macros so that it is possible to do:

   (top of file, before #includes)
   #define LOG_CATEGORY UCLASS_SPI

   (later in the file)
   log_info("message1");
   log_debug("message2");
   log_err("message3");

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

 include/log.h             | 14 ++++++++++++++
 test/log/log_test.c       | 13 +++++++++++++
 test/py/tests/test_log.py |  6 ++++++
 3 files changed, 33 insertions(+)

diff --git a/include/log.h b/include/log.h
index 61411b72eac..12168340d12 100644
--- a/include/log.h
+++ b/include/log.h
@@ -103,8 +103,22 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 		      __func__, \
 		      pr_fmt(_fmt), ##_args); \
 	})
+#define log_err(_fmt...)	log(LOG_CATEGORY, LOGL_ERR, ##_fmt)
+#define log_warning(_fmt...)	log(LOG_CATEGORY, LOGL_WARNING, ##_fmt)
+#define log_notice(_fmt...)	log(LOG_CATEGORY, LOGL_NOTICE, ##_fmt)
+#define log_info(_fmt...)	log(LOG_CATEGORY, LOGL_INFO, ##_fmt)
+#define log_debug(_fmt...)	log(LOG_CATEGORY, LOGL_DEBUG, ##_fmt)
+#define log_content(_fmt...)	log(LOG_CATEGORY, LOGL_DEBUG_CONTENT, ##_fmt)
+#define log_io(_fmt...)		log(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt)
 #else
 #define log(_cat, _level, _fmt, _args...)
+#define log_err(_fmt...)
+#define log_warning(_fmt...)
+#define log_notice(_fmt...)
+#define log_info(_fmt...)
+#define log_debug(_fmt...)
+#define log_content(_fmt...)
+#define log_io(_fmt...)
 #endif
 
 #ifdef DEBUG
diff --git a/test/log/log_test.c b/test/log/log_test.c
index de431b0823e..febc2c1252a 100644
--- a/test/log/log_test.c
+++ b/test/log/log_test.c
@@ -181,6 +181,19 @@ static int log_test(int testnum)
 			return ret;
 		break;
 	}
+	case 10: {
+		log_err("level %d\n", LOGL_EMERG);
+		log_err("level %d\n", LOGL_ALERT);
+		log_err("level %d\n", LOGL_CRIT);
+		log_err("level %d\n", LOGL_ERR);
+		log_warning("level %d\n", LOGL_WARNING);
+		log_notice("level %d\n", LOGL_NOTICE);
+		log_info("level %d\n", LOGL_INFO);
+		log_debug("level %d\n", LOGL_DEBUG);
+		log_content("level %d\n", LOGL_DEBUG_CONTENT);
+		log_io("level %d\n", LOGL_DEBUG_IO);
+		break;
+	}
 	}
 
 	return 0;
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index 605275b0399..cb183444c6f 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -85,6 +85,11 @@ def test_log(u_boot_console):
         lines = run_test(9)
         check_log_entries(lines, 3)
 
+    def test10():
+        lines = run_test(10)
+        for i in range(7):
+            assert 'log_test() level %d' % i == lines.next()
+
     # TODO(sjg at chromium.org): Consider structuring this as separate tests
     cons = u_boot_console
     test0()
@@ -97,6 +102,7 @@ def test_log(u_boot_console):
     test7()
     test8()
     test9()
+    test10()
 
 @pytest.mark.buildconfigspec('cmd_log')
 def test_log_format(u_boot_console):
-- 
2.19.0.605.g01d371f741-goog

  reply	other threads:[~2018-10-01 17:55 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 17:55 [U-Boot] [PATCH 00/15] sandbox: Add support for TPL and other improvements Simon Glass
2018-10-01 17:55 ` Simon Glass [this message]
2018-10-09 23:51   ` [U-Boot] [PATCH 01/15] log: Add helpers for common log levels sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 02/15] sandbox: Support file truncation with os_open() Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 03/15] sandbox: Add a way to write data to the host filesystem Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 04/15] sandbox: spi: Drop command-line SPI option Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 05/15] sandbox: Support booting from TPL to SPL Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 06/15] sandbox: Add a flag to set the default log level Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 07/15] sandbox: Remove the old memory file later Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 08/15] sandbox: spi: Add more logging Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 09/15] sandbox: video: Speed up video output Simon Glass
2018-10-01 19:20   ` Anatolij Gustschin
2018-10-09 23:51     ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 10/15] sandbox: Add a debug UART Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 11/15] serial: sandbox: Allow serial output without device tree Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 12/15] sandbox: tpm: Tidy up enums and return values Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 13/15] sandbox: tpm: Enhance to support the latest Chromium OS Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 14/15] dm: spi: Clean up detection of sandbox SPI emulator Simon Glass
2018-10-09 23:51   ` sjg at google.com
2018-10-01 17:55 ` [U-Boot] [PATCH 15/15] sandbox: Restore blocking I/O on exit Simon Glass
2018-10-09 23:51   ` sjg at google.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181001175520.239554-2-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox