[v1,03/10] lib/log: Add verbose logging routines

Message ID 70da1a43de28d88eaafe303a71db5ba33a464fdd.1531170563.git.geoff@infradead.org
State Superseded
Headers show
Series
  • [v1,01/10] docker: Add libfdt-dev
Related show

Commit Message

Geoff Levand July 9, 2018, 9:21 p.m.
Add three new logging routines pb_log_fn and pb_debug_fn, which
print the calling function's name to the log, and pb_debug_fl
which prints the calling function's name and the file line
number to the log.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 lib/log/log.c | 31 +++++++++++++++++++++++++++++++
 lib/log/log.h | 10 ++++++++++
 s             |  0
 3 files changed, 41 insertions(+)
 create mode 100644 s

diff --git a/s b/s
new file mode 100644
index 0000000..e69de29

Patch

diff --git a/lib/log/log.c b/lib/log/log.c
index 44543d0..4c832bc 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -23,6 +23,15 @@  void pb_log(const char *fmt, ...)
 	va_end(ap);
 }
 
+void _pb_log_fn(const char *func, const char *fmt, ...)
+{
+	va_list ap;
+	pb_log("%s: ", func);
+	va_start(ap, fmt);
+	__log(fmt, ap);
+	va_end(ap);
+}
+
 void pb_debug(const char *fmt, ...)
 {
 	va_list ap;
@@ -33,6 +42,28 @@  void pb_debug(const char *fmt, ...)
 	va_end(ap);
 }
 
+void _pb_debug_fn(const char *func, const char *fmt, ...)
+{
+	va_list ap;
+	if (!debug)
+		return;
+	pb_log("%s: ", func);
+	va_start(ap, fmt);
+	__log(fmt, ap);
+	va_end(ap);
+}
+
+void _pb_debug_fl(const char *func, int line, const char *fmt, ...)
+{
+	va_list ap;
+	if (!debug)
+		return;
+	pb_log("%s:%d: ", func, line);
+	va_start(ap, fmt);
+	__log(fmt, ap);
+	va_end(ap);
+}
+
 void __pb_log_init(FILE *fp, bool _debug)
 {
 	if (logf)
diff --git a/lib/log/log.h b/lib/log/log.h
index 9454596..2d4fd91 100644
--- a/lib/log/log.h
+++ b/lib/log/log.h
@@ -5,7 +5,17 @@ 
 #include <stdio.h>
 
 void __attribute__ ((format (printf, 1, 2))) pb_log(const char *fmt, ...);
+void __attribute__ ((format (printf, 2, 3))) _pb_log_fn(const char *func,
+	const char *fmt, ...);
+#define pb_log_fn(args...) _pb_log_fn(__func__, args)
+
 void __attribute__ ((format (printf, 1, 2))) pb_debug(const char *fmt, ...);
+void __attribute__ ((format (printf, 2, 3))) _pb_debug_fn(const char *func,
+	const char *fmt, ...);
+#define pb_debug_fn(args...) _pb_debug_fn(__func__, args)
+void __attribute__ ((format (printf, 3, 4))) _pb_debug_fl(const char *func,
+	int line, const char *fmt, ...);
+#define pb_debug_fl(args...) _pb_debug_fl(__func__, __LINE__, args)
 
 void __pb_log_init(FILE *stream, bool debug);