From dcfdc5567ecee2a4989ab445d213a67447158434 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 8 Nov 2015 02:33:22 +0100 Subject: [PATCH] core: Add logging functions for controller specific messages --- src/log.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++-------- src/log.h | 21 +++++++++++++---- 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/src/log.c b/src/log.c index f5a281a95..0442c26d8 100644 --- a/src/log.c +++ b/src/log.c @@ -85,7 +85,8 @@ static void logging_close(void) } } -static void logging_log(int priority, const char *format, va_list ap) +static void logging_log(uint16_t index, int priority, + const char *format, va_list ap) { char *ident = "bluetoothd"; uint8_t ident_len = strlen(ident) + 1; @@ -101,7 +102,7 @@ static void logging_log(int priority, const char *format, va_list ap) len = strlen(str) + 1; hdr.opcode = cpu_to_le16(0x0000); - hdr.index = cpu_to_le16(0xffff); + hdr.index = cpu_to_le16(index); hdr.len = cpu_to_le16(2 + ident_len + len); hdr.priority = priority; hdr.ident_len = ident_len; @@ -127,19 +128,19 @@ static void logging_log(int priority, const char *format, va_list ap) free(str); } -void info(const char *format, ...) +void error(const char *format, ...) { va_list ap; va_start(ap, format); - vsyslog(LOG_INFO, format, ap); + vsyslog(LOG_ERR, format, ap); va_end(ap); if (logging_fd < 0) return; va_start(ap, format); - logging_log(LOG_INFO, format, ap); + logging_log(HCI_DEV_NONE, LOG_ERR, format, ap); va_end(ap); } @@ -155,11 +156,27 @@ void warn(const char *format, ...) return; va_start(ap, format); - logging_log(LOG_WARNING, format, ap); + logging_log(HCI_DEV_NONE, LOG_WARNING, format, ap); va_end(ap); } -void error(const char *format, ...) +void info(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vsyslog(LOG_INFO, format, ap); + va_end(ap); + + if (logging_fd < 0) + return; + + va_start(ap, format); + logging_log(HCI_DEV_NONE, LOG_INFO, format, ap); + va_end(ap); +} + +void btd_error(uint16_t index, const char *format, ...) { va_list ap; @@ -171,11 +188,43 @@ void error(const char *format, ...) return; va_start(ap, format); - logging_log(LOG_ERR, format, ap); + logging_log(index, LOG_ERR, format, ap); + va_end(ap); +} + +void btd_warn(uint16_t index, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vsyslog(LOG_WARNING, format, ap); + va_end(ap); + + if (logging_fd < 0) + return; + + va_start(ap, format); + logging_log(index, LOG_WARNING, format, ap); + va_end(ap); +} + +void btd_info(uint16_t index, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vsyslog(LOG_INFO, format, ap); + va_end(ap); + + if (logging_fd < 0) + return; + + va_start(ap, format); + logging_log(index, LOG_INFO, format, ap); va_end(ap); } -void btd_debug(const char *format, ...) +void btd_debug(uint16_t index, const char *format, ...) { va_list ap; @@ -187,7 +236,7 @@ void btd_debug(const char *format, ...) return; va_start(ap, format); - logging_log(LOG_DEBUG, format, ap); + logging_log(index, LOG_DEBUG, format, ap); va_end(ap); } diff --git a/src/log.h b/src/log.h index bf9eac2aa..f40fb31e9 100644 --- a/src/log.h +++ b/src/log.h @@ -21,11 +21,20 @@ * */ -void info(const char *format, ...) __attribute__((format(printf, 1, 2))); -void warn(const char *format, ...) __attribute__((format(printf, 1, 2))); +#include + 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_debug(const char *format, ...) __attribute__((format(printf, 1, 2))); +void btd_error(uint16_t index, const char *format, ...) + __attribute__((format(printf, 2, 3))); +void btd_warn(uint16_t index, const char *format, ...) + __attribute__((format(printf, 2, 3))); +void btd_info(uint16_t index, const char *format, ...) + __attribute__((format(printf, 2, 3))); +void btd_debug(uint16_t index, const char *format, ...) + __attribute__((format(printf, 2, 3))); void __btd_log_init(const char *debug, int detach); void __btd_log_cleanup(void); @@ -49,11 +58,13 @@ void __btd_enable_debug(struct btd_debug_desc *start, * Simple macro around btd_debug() which also include the function * name it is called in. */ -#define DBG(fmt, arg...) do { \ +#define DBG_IDX(idx, fmt, arg...) do { \ static struct btd_debug_desc __btd_debug_desc \ __attribute__((used, section("__debug"), aligned(8))) = { \ .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \ }; \ if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \ - btd_debug("%s:%s() " fmt, __FILE__, __func__ , ## arg); \ + btd_debug(idx, "%s:%s() " fmt, __FILE__, __func__ , ## arg); \ } while (0) + +#define DBG(fmt, arg...) DBG_IDX(0xffff, fmt, ## arg) -- 2.47.3