I think in most cases tags will not be used and it will
just be a pain inserting ", 0". But if someone wants to use
tags like this then they still can via qb_logt()
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qblog.h | 48 +++++++++++++++++++++++++++++++++---------------
lib/log.c | 2 +-
lib/log_blackbox.c | 2 +-
lib/util_int.h | 4 ++--
tests/bench-log.c | 8 ++++----
tests/simple-log.c | 28 ++++++++++++++--------------
6 files changed, 55 insertions(+), 37 deletions(-)
diff --git a/include/qb/qblog.h b/include/qb/qblog.h
index e931652..350b580 100644
--- a/include/qb/qblog.h
+++ b/include/qb/qblog.h
@@ -49,7 +49,7 @@ extern "C" {
* main() {
* qb_log_init("simple-log", LOG_DAEMON, LOG_INFO);
* // ...
- * qb_log(LOG_WARNING, 0, "watch out");
+ * qb_log(LOG_WARNING, "watch out");
* // ...
* qb_log_fini();
* }
@@ -112,7 +112,7 @@ extern "C" {
* // call this after you fork()
* qb_log_thread_start();
* // ...
- * qb_log(LOG_WARNING, 0, "watch out");
+ * qb_log(LOG_WARNING, "watch out");
* // ...
* qb_log_fini();
* }
@@ -146,20 +146,22 @@ extern "C" {
* qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, 1024*10);
* qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE);
* // ...
- * qb_log(LOG_WARNING, 0, "watch out");
+ * qb_log(LOG_WARNING, "watch out");
* // ...
* qb_log_fini();
* }
* @endcode
*
* @par Tagging messages.
- * You can tag messages (again a bit field) using the second argument
- * to qb_log(). this can be used to add feature or sub-system information
- * to the logs.
+ * You can tag messages using the second argument to qb_logt() or
+ * by using qb_log_filter_ctl().
+ * This can be used to add feature or sub-system information to the logs.
*
* @code
* const char* my_tags_stringify(uint32_t tags) {
- * if (qb_bit_is_set(tags, 3) {
+ * if (qb_bit_is_set(tags, QB_LOG_TAG_LIBQB_MSG_BIT) {
+ * return "libqb";
+ * } else if (tags == 3) {
* return "three";
* } else {
* return "MAIN";
@@ -170,12 +172,13 @@ extern "C" {
* qb_log_tags_stringify_fn_set(my_tags_stringify);
* qb_log_format_set(QB_LOG_STDERR, "[%5g] %p %b");
* // ...
- * qb_log(LOG_INFO, (1<<3), "hello");
- * qb_log(LOG_INFO, 0, "hello");
+ * qb_logt(LOG_INFO, 3, "hello");
+ * qb_logt(LOG_INFO, 0, "hello");
* }
* @endcode
* The code above will produce:
* @code
+ * [libqb] some message
* [three] info hello
* [MAIN ] info hello
* @endcode
@@ -210,7 +213,7 @@ extern struct qb_log_callsite __stop___verbose[];
/**
- * Internal function: use qb_log()
+ * Internal function: use qb_log() or qb_logt()
*/
void qb_log_real_(struct qb_log_callsite *cs, ...);
@@ -246,10 +249,11 @@ void qb_log_from_external_source(const char *function,
/**
- * This is the main function to generate a log message.
+ * This is the function to generate a log message if you want to
+ * manually add tags.
*
* @param priority this takes syslog priorities.
- * @param tags this is a bit field that you can use with
+ * @param tags this is a uint32_t that you can use with
* qb_log_tags_stringify_fn_set() to "tag" a log message
* with a feature or sub-system then you can use "%g"
* in the format specifer to print it out.
@@ -257,16 +261,30 @@ void qb_log_from_external_source(const char *function,
* @param args usual printf style args
*/
#ifndef S_SPLINT_S
-#define qb_log(priority, tags, fmt, args...) do { \
+#define qb_logt(priority, tags, fmt, args...) do { \
static struct qb_log_callsite descriptor \
__attribute__((section("__verbose"), aligned(8))) = \
{ __func__, __FILE__, fmt, priority, __LINE__, 0, tags }; \
qb_log_real_(&descriptor, ##args); \
} while(0)
#else
+#define qb_logt
+#endif
+
+/**
+ * This is the main function to generate a log message.
+ *
+ * @param priority this takes syslog priorities.
+ * @param fmt usual printf style format specifiers
+ * @param args usual printf style args
+ */
+#ifndef S_SPLINT_S
+#define qb_log(priority, fmt, args...) qb_logt(priority, 0, fmt, ##args)
+#else
#define qb_log
#endif
+
/**
* This is similar to perror except it goes into the logging system.
*
@@ -276,9 +294,9 @@ void qb_log_from_external_source(const char *function,
* @param args usual printf style args
*/
#ifndef S_SPLINT_S
-#define qb_perror(priority, tags, fmt, args...) do { \
+#define qb_perror(priority, fmt, args...) do { \
const char *err = strerror(errno); \
- qb_log(priority, tags, fmt ": %s (%d)", ##args, err, errno); \
+ qb_logt(priority, 0, fmt ": %s (%d)", ##args, err, errno); \
} while(0)
#else
#define qb_perror
diff --git a/lib/log.c b/lib/log.c
index 89f4cf4..5aa04ce 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -337,7 +337,7 @@ _log_so_walk_callback(struct dl_phdr_info *info, size_t size, void
*data)
handle = dlopen(info->dlpi_name, RTLD_LAZY);
error = dlerror();
if (!handle || error) {
- qb_log(LOG_ERR, 0, "%s", error);
+ qb_log(LOG_ERR, "%s", error);
if(handle) {
dlclose(handle);
}
diff --git a/lib/log_blackbox.c b/lib/log_blackbox.c
index 2bc8d01..2e50afe 100644
--- a/lib/log_blackbox.c
+++ b/lib/log_blackbox.c
@@ -136,7 +136,7 @@ void qb_log_blackbox_print_from_file(const char *bb_filename)
fd = open(bb_filename, O_CREAT | O_RDWR, 0700);
if (fd < 0) {
- qb_perror(LOG_ERR, 0, "qb_log_blackbox_print_from_file");
+ qb_perror(LOG_ERR, "qb_log_blackbox_print_from_file");
return;
}
instance = qb_rb_create_from_file(fd, 0);
diff --git a/lib/util_int.h b/lib/util_int.h
index 88e528d..0a3f1ff 100644
--- a/lib/util_int.h
+++ b/lib/util_int.h
@@ -29,7 +29,7 @@
* destinguished from external ones.
*/
#ifndef S_SPLINT_S
-#define qb_util_log(priority, fmt, args...) qb_log(priority, QB_LOG_TAG_LIBQB_MSG, fmt,
##args)
+#define qb_util_log(priority, fmt, args...) qb_logt(priority, QB_LOG_TAG_LIBQB_MSG, fmt,
##args)
#else
#define qb_util_log
#endif
@@ -37,7 +37,7 @@
#ifndef S_SPLINT_S
#define qb_util_perror(priority, fmt, args...) do { \
const char *err = strerror(errno); \
- qb_log(priority, QB_LOG_TAG_LIBQB_MSG, fmt ": %s (%d)", ##args, err, errno);
\
+ qb_logt(priority, QB_LOG_TAG_LIBQB_MSG, fmt ": %s (%d)", ##args, err, errno);
\
} while(0)
#else
#define qb_util_perror
diff --git a/tests/bench-log.c b/tests/bench-log.c
index 48d641c..9351431 100644
--- a/tests/bench-log.c
+++ b/tests/bench-log.c
@@ -91,21 +91,21 @@ int main (void)
printf ("heating up cache with qb_log functionality\n");
for (i = 0; i < ITERATIONS; i++) {
- qb_log(LOG_DEBUG, 0, "hello");
+ qb_log(LOG_DEBUG, "hello");
}
bm_start();
for (i = 0; i < ITERATIONS; i++) {
- qb_log(LOG_DEBUG, 0, "RecordA");
+ qb_log(LOG_DEBUG, "RecordA");
}
bm_finish ("qb_log 1 arguments:");
bm_start();
for (i = 0; i < ITERATIONS; i++) {
- qb_log(LOG_DEBUG, 0, "%s%s", "RecordA", "RecordB");
+ qb_log(LOG_DEBUG, "%s%s", "RecordA", "RecordB");
}
bm_finish ("qb_log 2 arguments:");
bm_start();
for (i = 0; i < ITERATIONS; i++) {
- qb_log(LOG_DEBUG, 0, "%s%s%s", "RecordA", "RecordB",
"RecordC");
+ qb_log(LOG_DEBUG, "%s%s%s", "RecordA", "RecordB",
"RecordC");
}
bm_finish ("qb_log 3 arguments:");
diff --git a/tests/simple-log.c b/tests/simple-log.c
index 0e10204..e507e0f 100644
--- a/tests/simple-log.c
+++ b/tests/simple-log.c
@@ -31,22 +31,22 @@
static void func_one(void) {
FILE* fd;
- qb_log(LOG_DEBUG, MY_TAG_TWO, "arf arf?");
- qb_log(LOG_CRIT, MY_TAG_THREE, "arrrg!");
- qb_log(LOG_ERR, MY_TAG_THREE, "oops, I did it again");
- qb_log(LOG_INFO, 0, "are you aware ...");
+ qb_logt(LOG_DEBUG, MY_TAG_TWO, "arf arf?");
+ qb_logt(LOG_CRIT, MY_TAG_THREE, "arrrg!");
+ qb_logt(LOG_ERR, MY_TAG_THREE, "oops, I did it again");
+ qb_log(LOG_INFO, "are you aware ...");
fd = fopen("/nothing.txt", "r+");
if (fd == NULL) {
- qb_perror(LOG_ERR, 0, "can't open(\"/nothing.txt\")");
+ qb_perror(LOG_ERR, "can't open(\"/nothing.txt\")");
}
}
static void func_two(void) {
- qb_log(LOG_DEBUG, 0, "arf arf?");
- qb_log(LOG_CRIT, MY_TAG_ONE, "arrrg!");
- qb_log(LOG_ERR, 0, "oops, I did it again");
- qb_log(LOG_INFO, MY_TAG_THREE, "are you aware ...");
+ qb_logt(LOG_DEBUG, 0, "arf arf?");
+ qb_logt(LOG_CRIT, MY_TAG_ONE, "arrrg!");
+ qb_log(LOG_ERR, "oops, I did it again");
+ qb_logt(LOG_INFO, MY_TAG_THREE, "are you aware ...");
}
static void show_usage(const char *name)
@@ -167,16 +167,16 @@ int32_t main(int32_t argc, char *argv[])
if (do_threaded) {
qb_log_thread_start();
}
- qb_log(LOG_DEBUG, 0, "hello");
- qb_log(LOG_INFO, 0, "this is an info");
- qb_log(LOG_NOTICE, 0, "hello - notice?");
+ qb_log(LOG_DEBUG, "hello");
+ qb_log(LOG_INFO, "this is an info");
+ qb_log(LOG_NOTICE, "hello - notice?");
func_one();
func_two();
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
- qb_log(LOG_WARNING, 0, "no syslog");
- qb_log(LOG_ERR, 0, "no syslog");
+ qb_log(LOG_WARNING, "no syslog");
+ qb_log(LOG_ERR, "no syslog");
#if 0
// test blackbox
--
1.7.4