All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v3 1/9] log: Don't log __FILE__ and __func__ with DBG_IDX
@ 2022-03-23 20:13 Luiz Augusto von Dentz
  2022-03-23 20:13 ` [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED Luiz Augusto von Dentz
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2022-03-23 20:13 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This removes __FILE__ and __func__ from DBG_IDX since users of it may
already contain such information embedded in the format.
---
 src/log.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/log.h b/src/log.h
index 74941beb2..a244fc4d8 100644
--- a/src/log.h
+++ b/src/log.h
@@ -9,6 +9,7 @@
  */
 
 #include <stdint.h>
+#include <stdbool.h>
 
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
@@ -52,10 +53,11 @@ void __btd_enable_debug(struct btd_debug_desc *start,
 		.file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
 	}; \
 	if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
-		btd_debug(idx, "%s:%s() " fmt, __FILE__, __func__ , ## arg); \
+		btd_debug(idx, fmt, ## arg); \
 } while (0)
 
-#define DBG(fmt, arg...) DBG_IDX(0xffff, fmt, ## arg)
+#define DBG(fmt, arg...) \
+	DBG_IDX(0xffff, "%s:%s() " fmt, __FILE__, __func__ , ## arg)
 #define error(fmt, arg...) \
 	btd_error(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg)
 #define warn(fmt, arg...) \
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread
* [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED
@ 2022-03-23  0:06 Luiz Augusto von Dentz
  2022-03-23 10:35 ` Marcel Holtmann
  0 siblings, 1 reply; 15+ messages in thread
From: Luiz Augusto von Dentz @ 2022-03-23  0:06 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This introduces DBG_IS_ENABLE macro which can be used to check if
BTD_DEBUG_FLAG_PRINT has been enabled for the current file.
---
 src/log.c | 12 ++++++++++++
 src/log.h | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/src/log.c b/src/log.c
index 0155a6bba..1157859ef 100644
--- a/src/log.c
+++ b/src/log.c
@@ -179,6 +179,18 @@ void __btd_log_init(const char *debug, int detach)
 	info("Bluetooth daemon %s", VERSION);
 }
 
+bool __btd_log_is_enabled(const char *file)
+{
+	struct btd_debug_desc *desc;
+
+	for (desc = __start___debug; desc < __stop___debug; desc++) {
+		if (desc->file && g_pattern_match_simple(file, desc->file))
+			return desc->flags & BTD_DEBUG_FLAG_PRINT;
+	}
+
+	return false;
+}
+
 void __btd_log_cleanup(void)
 {
 	closelog();
diff --git a/src/log.h b/src/log.h
index 74941beb2..e35238870 100644
--- a/src/log.h
+++ b/src/log.h
@@ -9,6 +9,7 @@
  */
 
 #include <stdint.h>
+#include <stdbool.h>
 
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
@@ -27,6 +28,7 @@ void btd_debug(uint16_t index, const char *format, ...)
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
 void __btd_toggle_debug(void);
+bool __btd_log_is_enabled(const char *file);
 
 struct btd_debug_desc {
 	const char *file;
@@ -38,6 +40,15 @@ struct btd_debug_desc {
 void __btd_enable_debug(struct btd_debug_desc *start,
 					struct btd_debug_desc *stop);
 
+/* DBG_IS_ENABLED:
+ *
+ * Simple macro that can be used to check if debug has been enabled for the
+ * __FILE__.
+ * Note: This does a lookup thus why it was not used by the likes of
+ * DBG/DBG_IDX which loads it directly from section("__debug").
+ */
+#define DBG_IS_ENABLED() __btd_log_is_enabled(__FILE__)
+
 /**
  * DBG:
  * @fmt: format string
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-03-24 19:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 20:13 [PATCH BlueZ v3 1/9] log: Don't log __FILE__ and __func__ with DBG_IDX Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED Luiz Augusto von Dentz
2022-03-24  1:53   ` [BlueZ,v2,1/9] " bluez.test.bot
2022-03-24 19:50   ` [PATCH BlueZ v2 1/9] " patchwork-bot+bluetooth
2022-03-23 20:13 ` [PATCH BlueZ v3 2/9] mgmt: Add DBG macro Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 3/9] mgmt: Introduce mgmt_set_verbose Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 4/9] adapter: Don't use DBG in mgmt_debug Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 5/9] att: Log file and function names Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 6/9] gatt-client: Add DBG macro Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 7/9] gatt-server: " Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 8/9] att: Rename att_debug and att_verbose to DBG and VERBOSE Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 9/9] device: Don't use DBG in gatt_debug Luiz Augusto von Dentz
2022-03-23 21:48 ` [BlueZ,v3,1/9] log: Don't log __FILE__ and __func__ with DBG_IDX bluez.test.bot
  -- strict thread matches above, loose matches on Subject: below --
2022-03-23  0:06 [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED Luiz Augusto von Dentz
2022-03-23 10:35 ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.