[U-Boot] [PATCH v2 04/34] log: Allow #define LOG_DEBUG to enable logging in a file

Simon Glass sjg at chromium.org
Sun Feb 17 03:24:37 UTC 2019


At present it is possible to '#define DEBUG' at the top of a file which
causes all debug() statements in that file to become active. There is
currently no equivalent with logging, but this is a useful function.

Add a LOG_DEBUG define along with documentation.

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

Changes in v2:
- Add a note as to why the default log level must be set to LOGL_DEBUG

 doc/README.log | 15 +++++++++++++++
 include/log.h  |  7 ++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/doc/README.log b/doc/README.log
index 75350ecd41d..19856d43da2 100644
--- a/doc/README.log
+++ b/doc/README.log
@@ -69,6 +69,21 @@ If CONFIG_LOG is not set, then no logging will be available.
 The above have SPL versions also, e.g. CONFIG_SPL_MAX_LOG_LEVEL.
 
 
+Temporary logging within a single file
+--------------------------------------
+
+Sometimes it is useful to turn on logging just in one file. You can use this:
+
+   #define LOG_DEBUG
+
+to enable building in of all logging statements in a single file. Put it at
+the top of the file, before any #includes.
+
+To actually get U-Boot to output this you need to also set the default logging
+level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (LOGL_DEBUG) or more. Otherwise
+debug output is suppressed and will not be generated.
+
+
 Convenience functions
 ---------------------
 
diff --git a/include/log.h b/include/log.h
index 33e99ab7030..7566ba7f2db 100644
--- a/include/log.h
+++ b/include/log.h
@@ -111,11 +111,16 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 #endif
 
 #if CONFIG_IS_ENABLED(LOG)
+#ifdef LOG_DEBUG
+#define _LOG_DEBUG	1
+#else
+#define _LOG_DEBUG	0
+#endif
 
 /* Emit a log record if the level is less that the maximum */
 #define log(_cat, _level, _fmt, _args...) ({ \
 	int _l = _level; \
-	if (CONFIG_IS_ENABLED(LOG) && _l <= _LOG_MAX_LEVEL) \
+	if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \
 		_log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \
 		      __func__, \
 		      pr_fmt(_fmt), ##_args); \
-- 
2.21.0.rc0.258.g878e2cd30e-goog



More information about the U-Boot mailing list