Skip to contentSkip to conversation

log: Make error and warn log file and function information

PATCH In review Luiz Augusto von Dentz 1 participant 2 messages Apr 29, 2020 – May 1, 2020 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 log: Make error and warn log file and function information

From: Luiz Augusto von Dentz <[email protected]>

This makes it a lot simpler to find out where errors/warnings come from and also remove the possibility of clashes when having multiple places where the message would be exactly the same.

---
 src/log.c | 26 --------------------------
 src/log.h |  6 ++++--
 2 files changed, 4 insertions(+), 28 deletions(-)
src/log.c +0 -26
index 11d26d508..a42c5941d 100644
@@ -53,32 +53,6 @@ static void monitor_log(uint16_t index, int priority,
 	bt_log_vprintf(index, LOG_IDENT, priority, format, ap);
 }
 
-void error(const char *format, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-	vsyslog(LOG_ERR, format, ap);
-	va_end(ap);
-
-	va_start(ap, format);
-	monitor_log(HCI_DEV_NONE, LOG_ERR, format, ap);
-	va_end(ap);
-}
-
-void warn(const char *format, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-	vsyslog(LOG_WARNING, format, ap);
-	va_end(ap);
-
-	va_start(ap, format);
-	monitor_log(HCI_DEV_NONE, LOG_WARNING, format, ap);
-	va_end(ap);
-}
-
 void info(const char *format, ...)
 {
 	va_list ap;
src/log.h +4 -2
index 0d243ceca..e83431151 100644
@@ -23,8 +23,6 @@
 
 #include <stdint.h>
 
-void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
-void warn(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void btd_log(uint16_t index, int priority, const char *format, ...)
@@ -71,3 +69,7 @@ void __btd_enable_debug(struct btd_debug_desc *start,
 } while (0)
 
 #define DBG(fmt, arg...) DBG_IDX(0xffff, fmt, ## arg)
+#define error(fmt, arg...) \
+	btd_error(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg)
+#define warn(fmt, arg...) \
+	btd_warn(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg)
Signature · 1 line
2.25.3
author maintainer
#1 lore raw

Hi,

Quoted 70 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This makes it a lot simpler to find out where errors/warnings come from and also remove the possibility of clashes when having multiple places where the message would be exactly the same.

---
 src/log.c | 26 --------------------------
 src/log.h |  6 ++++--
 2 files changed, 4 insertions(+), 28 deletions(-)
src/log.c +0 -26
index 11d26d508..a42c5941d 100644
@@ -53,32 +53,6 @@ static void monitor_log(uint16_t index, int priority,
        bt_log_vprintf(index, LOG_IDENT, priority, format, ap);
 }
 
-void error(const char *format, ...)
-{
-       va_list ap;
-
-       va_start(ap, format);
-       vsyslog(LOG_ERR, format, ap);
-       va_end(ap);
-
-       va_start(ap, format);
-       monitor_log(HCI_DEV_NONE, LOG_ERR, format, ap);
-       va_end(ap);
-}
-
-void warn(const char *format, ...)
-{
-       va_list ap;
-
-       va_start(ap, format);
-       vsyslog(LOG_WARNING, format, ap);
-       va_end(ap);
-
-       va_start(ap, format);
-       monitor_log(HCI_DEV_NONE, LOG_WARNING, format, ap);
-       va_end(ap);
-}
-
 void info(const char *format, ...)
 {
        va_list ap;
src/log.h +4 -3
index 0d243ceca..e83431151 100644
@@ -23,8 +23,6 @@
 
 #include <stdint.h>
 
-void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
-void warn(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void btd_log(uint16_t index, int priority, const char *format, ...)
@@ -71,3 +69,7 @@ void __btd_enable_debug(struct btd_debug_desc *start,
 } while (0)
 
 #define DBG(fmt, arg...) DBG_IDX(0xffff, fmt, ## arg)
+#define error(fmt, arg...) \
+       btd_error(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg)
+#define warn(fmt, arg...) \
+       btd_warn(0xffff, "%s:%s() " fmt, __FILE__, __func__, ## arg)
--
Quoted 1 line

2.25.3

Pushed.

Signature · 1 line
Luiz Augusto von Dentz