Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbutil.h | 12 ++++++++++++
lib/Makefile.am | 2 +-
lib/util.c | 32 ++++++++++++++++++++++++++++++++
lib/util_int.h | 35 +++++++++++++++++++++++++++++++++++
4 files changed, 80 insertions(+), 1 deletions(-)
create mode 100644 lib/util_int.h
diff --git a/include/qb/qbutil.h b/include/qb/qbutil.h
index d6c9987..09ffa65 100644
--- a/include/qb/qbutil.h
+++ b/include/qb/qbutil.h
@@ -51,5 +51,17 @@ int32_t qb_thread_trylock (qb_thread_lock_t* tl);
*/
int32_t qb_thread_unlock (qb_thread_lock_t* tl);
+
+typedef void (* qb_util_log_fn_t)(const char *file_name,
+ int32_t file_line,
+ int32_t severity,
+ const char *msg);
+
+/**
+ * Use this function output libqb internal log message as you wish.
+ */
+void qb_util_set_log_function (qb_util_log_fn_t fn);
+
+
#endif /* QB_UTIL_H_DEFINED */
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9582341..ee2a7c4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -21,7 +21,7 @@
MAINTAINERCLEANFILES = Makefile.in
-noinst_HEADERS = ipc_int.h
+noinst_HEADERS = ipc_int.h util_int.h
#pkgconfigdir = $(libdir)/pkgconfig
#pkgconfig_DATA = libqbhash.pc
diff --git a/lib/util.c b/lib/util.c
index 1fcac7f..f9acd5b 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -21,6 +21,8 @@
#include <config.h>
#include "os_base.h"
+#include "util_int.h"
+#include <stdarg.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include <pthread.h>
@@ -107,4 +109,34 @@ int32_t qb_thread_trylock (qb_thread_lock_t* tl)
}
+/*
+ * ---------------------------------------------------
+ * Logging functions for the library.
+ */
+static qb_util_log_fn_t real_log_fn = NULL;
+
+void _qb_util_log (const char *file_name,
+ int32_t file_line,
+ int32_t severity,
+ const char *format,
+ ...)
+{
+ if (real_log_fn) {
+ va_list ap;
+ char msg[256];
+
+ va_start (ap, format);
+ vsnprintf (msg, 256, format, ap);
+ va_end (ap);
+
+ real_log_fn (file_name, file_line, severity, msg);
+ }
+}
+
+
+void qb_util_set_log_function (qb_util_log_fn_t fn)
+{
+ real_log_fn = fn;
+}
+
diff --git a/lib/util_int.h b/lib/util_int.h
new file mode 100644
index 0000000..d91f205
--- /dev/null
+++ b/lib/util_int.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * Author: Angus Salkeld <asalkeld(a)redhat.com>
+ *
+ * libqb is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * libqb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libqb. If not, see <
http://www.gnu.org/licenses/>.
+ */
+
+#ifndef QB_UTIL_INT_H_DEFINED
+#define QB_UTIL_INT_H_DEFINED
+
+#define qb_util_log(severity, args...) \
+do { \
+ _qb_util_log (__FILE__, __LINE__, severity, ##args); \
+} while(0)
+
+void _qb_util_log (const char *file_name,
+ int32_t file_line,
+ int32_t severity,
+ const char *format,
+ ...);
+
+#endif /* QB_UTIL_INT_H_DEFINED */
+
--
1.6.6.1