Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qblog.h | 48 +++++++++++++++++++++++++++++++++++-------------
lib/log.c | 47 ++++++++++++++++++++++++++++++++++++-----------
2 files changed, 71 insertions(+), 24 deletions(-)
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index 7a8c66d..1b88f18 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -228,11 +228,11 @@ typedef const char *(*qb_log_tags_stringify_fn)(uint32_t tags);
* the special section is treated as an array of these.
*/
struct qb_log_callsite {
- const char *function;
- const char *filename;
- const char *format;
+ const char *function;
+ const char *filename;
+ const char *format;
uint8_t priority;
- uint32_t lineno;
+ uint32_t lineno;
uint32_t targets;
uint32_t tags;
} __attribute__((aligned(8)));
@@ -287,13 +287,32 @@ void qb_log_from_external_source(const char *function,
uint32_t tags,
...);
+/**
+ * Get or create a callsite at the give position.
+ *
+ * The result can then be passed into qb_log_real_()
+ *
+ * @param function originating function name
+ * @param filename originating filename
+ * @param format format string
+ * @param priority this takes syslog priorities.
+ * @param lineno file line number
+ * @param tags the tag
+ */
+struct qb_log_callsite* qb_log_callsite_get(const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno,
+ uint32_t tags);
+
void qb_log_from_external_source_va(const char *function,
- const char *filename,
- const char *format,
- uint8_t priority,
- uint32_t lineno,
- uint32_t tags,
- va_list ap);
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno,
+ uint32_t tags,
+ va_list ap);
/**
* This is the function to generate a log message if you want to
@@ -315,12 +334,15 @@ void qb_log_from_external_source_va(const char *function,
qb_log_real_(&descriptor, ##args); \
} while(0)
#else
-#define qb_logt(priority, tags, fmt, args...) do { \
- qb_log_from_external_source(__func__, __FILE__, fmt, priority, \
- __LINE__, tags, ##args); \
+#define qb_logt(priority, tags, fmt, args...) do { \
+ struct qb_log_callsite* descriptor_pt = \
+ qb_log_callsite_get(__func__, __FILE__, fmt, \
+ priority, __LINE__, tags); \
+ qb_log_real_(descriptor_pt, ##args); \
} while(0)
#endif /* QB_HAVE_ATTRIBUTE_SECTION */
+
/**
* This is the main function to generate a log message.
*
diff --git a/lib/log.c b/lib/log.c
index 0101bc6..4056b1f 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -133,7 +133,7 @@ qb_log_real_va_(struct qb_log_callsite *cs, va_list ap)
char *str = buf;
va_list ap_copy;
- if (in_logger) {
+ if (in_logger || cs == NULL) {
return;
}
in_logger = QB_TRUE;
@@ -234,12 +234,13 @@ qb_log_thread_log_write(struct qb_log_callsite *cs,
}
}
-void
-qb_log_from_external_source_va(const char *function,
- const char *filename,
- const char *format,
- uint8_t priority,
- uint32_t lineno, uint32_t tags, va_list ap)
+struct qb_log_callsite*
+qb_log_callsite_get(const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno,
+ uint32_t tags)
{
struct qb_log_target *t;
struct qb_log_filter *flt;
@@ -249,13 +250,13 @@ qb_log_from_external_source_va(const char *function,
int32_t pos;
if (!logger_inited) {
- return;
+ return NULL;
}
cs = qb_log_dcs_get(&new_dcs, function, filename,
format, priority, lineno, tags);
if (cs == NULL) {
- return;
+ return NULL;
}
if (new_dcs) {
@@ -287,6 +288,24 @@ qb_log_from_external_source_va(const char *function,
}
pthread_rwlock_unlock(&_listlock);
}
+ return cs;
+}
+
+void
+qb_log_from_external_source_va(const char *function,
+ const char *filename,
+ const char *format,
+ uint8_t priority,
+ uint32_t lineno, uint32_t tags, va_list ap)
+{
+ struct qb_log_callsite *cs;
+
+ if (!logger_inited) {
+ return;
+ }
+
+ cs = qb_log_callsite_get(function, filename,
+ format, priority, lineno, tags);
qb_log_real_va_(cs, ap);
}
@@ -297,11 +316,17 @@ qb_log_from_external_source(const char *function,
uint8_t priority,
uint32_t lineno, uint32_t tags, ...)
{
+ struct qb_log_callsite *cs;
va_list ap;
+ if (!logger_inited) {
+ return;
+ }
+
+ cs = qb_log_callsite_get(function, filename,
+ format, priority, lineno, tags);
va_start(ap, tags);
- qb_log_from_external_source_va(function, filename, format, priority,
- lineno, tags, ap);
+ qb_log_real_va_(cs, ap);
va_end(ap);
}
--
1.7.9.1