And remove uses of it from the test programs
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
include/qb/qbutil.h | 3 +-
tests/bmc.c | 54 +++++++++++++++----------------
tests/bms.c | 86 ++++++++++++++++++++++++--------------------------
tests/check_log.c | 11 +-----
tests/loop.c | 49 +++++++++++++---------------
tests/rbreader.c | 40 ++++++++++++++++-------
tests/rbwriter.c | 25 ++++++++-------
7 files changed, 135 insertions(+), 133 deletions(-)
diff --git a/include/qb/qbutil.h b/include/qb/qbutil.h
index 2b450e9..16e6817 100644
--- a/include/qb/qbutil.h
+++ b/include/qb/qbutil.h
@@ -32,6 +32,7 @@ extern "C" {
#ifndef S_SPLINT_S
#include <unistd.h>
#endif /* S_SPLINT_S */
+#include <qb/qbdefs.h>
/**
* @file qbutil.h
@@ -88,7 +89,7 @@ typedef void (*qb_util_log_fn_t) (const char *file_name,
/**
* Use this function to output libqb internal log message as you wish.
*/
-void qb_util_set_log_function(qb_util_log_fn_t fn);
+void qb_util_set_log_function(qb_util_log_fn_t fn) QB_GNUC_DEPRECATED;
/**
* Add milliseconds onto the timespec.
diff --git a/tests/bmc.c b/tests/bmc.c
index 6a4eeb4..585811c 100644
--- a/tests/bmc.c
+++ b/tests/bmc.c
@@ -21,7 +21,7 @@
#include "os_base.h"
#include <signal.h>
-#include <qb/qbdefs.h>
+#include <qb/qblog.h>
#include <qb/qbutil.h>
#include <qb/qbipcc.h>
@@ -45,8 +45,8 @@ static void bm_finish(const char *operation, int32_t size)
ops_per_sec = ((float)ITERATIONS) / elapsed;
mbs_per_sec = ((((float)ITERATIONS) * size) / elapsed) / (1024.0 * 1024.0);
- printf("write size, %d, OPs/sec, %9.3f, ", size, ops_per_sec);
- printf("MB/sec, %9.3f\n", mbs_per_sec);
+ qb_log(LOG_INFO, "write size, %d, OPs/sec, %9.3f, MB/sec, %9.3f",
+ size, ops_per_sec, mbs_per_sec);
}
struct my_req {
@@ -70,11 +70,11 @@ repeat_send:
if (res == -EAGAIN) {
goto repeat_send;
} else if (res == -EINVAL || res == -EINTR || res == -ENOTCONN) {
- perror("qb_ipcc_send");
+ qb_perror(LOG_ERR, "qb_ipcc_send");
return -1;
} else {
errno = -res;
- perror("qb_ipcc_send");
+ qb_perror(LOG_ERR, "qb_ipcc_send");
goto repeat_send;
}
}
@@ -87,7 +87,7 @@ repeat_send:
return -1;
}
if (res < 0) {
- perror("qb_ipcc_recv");
+ qb_perror(LOG_ERR, "qb_ipcc_recv");
}
assert(res == sizeof(struct qb_ipc_response_header));
assert(res_header.id == 13);
@@ -101,7 +101,7 @@ repeat_send:
return -1;
}
if (res < 0) {
- perror("qb_ipcc_event_recv");
+ qb_perror(LOG_ERR, "qb_ipcc_event_recv");
}
assert(res == sizeof(struct qb_ipc_response_header));
assert(res_header.id == 13);
@@ -114,33 +114,27 @@ struct qb_ipc_request_header *global_zcb_buffer;
static void show_usage(const char *name)
{
- printf("usage: \n");
- printf("%s <options>\n", name);
- printf("\n");
- printf(" options:\n");
- printf("\n");
- printf(" -n non-blocking ipc (default blocking)\n");
- printf(" -e receive events\n");
- printf(" -v verbose\n");
- printf(" -h show this help text\n");
- printf("\n");
+ qb_log(LOG_INFO, "usage: \n");
+ qb_log(LOG_INFO, "%s <options>\n", name);
+ qb_log(LOG_INFO, "\n");
+ qb_log(LOG_INFO, " options:\n");
+ qb_log(LOG_INFO, "\n");
+ qb_log(LOG_INFO, " -n non-blocking ipc (default blocking)\n");
+ qb_log(LOG_INFO, " -e receive events\n");
+ qb_log(LOG_INFO, " -v verbose\n");
+ qb_log(LOG_INFO, " -h show this help text\n");
+ qb_log(LOG_INFO, "\n");
}
static void sigterm_handler(int32_t num)
{
- printf("bmc: %s(%d)\n", __func__, num);
+ qb_log(LOG_INFO, "bmc: %s(%d)\n", __func__, num);
qb_ipcc_disconnect(conn);
exit(0);
}
-static void libqb_log_writer(const char *file_name,
- int32_t file_line,
- int32_t severity, const char *msg)
-{
- printf("libqb: %s:%d [%d] %s\n", file_name, file_line, severity, msg);
-}
-
-int32_t main(int32_t argc, char *argv[])
+int32_t
+main(int32_t argc, char *argv[])
{
const char *options = "nevh";
int32_t opt;
@@ -149,7 +143,11 @@ int32_t main(int32_t argc, char *argv[])
mypid = getpid();
- qb_util_set_log_function(libqb_log_writer);
+ qb_log_init("bmc", LOG_USER, LOG_EMERG);
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
+ qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FILE, "*", LOG_INFO);
+ qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
while ((opt = getopt(argc, argv, options)) != -1) {
switch (opt) {
@@ -175,7 +173,7 @@ int32_t main(int32_t argc, char *argv[])
signal(SIGTERM, sigterm_handler);
conn = qb_ipcc_connect("bm1", MAX_MSG_SIZE);
if (conn == NULL) {
- perror("qb_ipcc_connect");
+ qb_perror(LOG_ERR, "qb_ipcc_connect");
exit(1);
}
diff --git a/tests/bms.c b/tests/bms.c
index cade87b..4583dcf 100644
--- a/tests/bms.c
+++ b/tests/bms.c
@@ -22,6 +22,7 @@
#include <signal.h>
#include <qb/qbdefs.h>
+#include <qb/qblog.h>
#include <qb/qbutil.h>
#include <qb/qbloop.h>
#include <qb/qbipcs.h>
@@ -46,12 +47,12 @@ static int32_t s1_connection_accept_fn(qb_ipcs_connection_t *c, uid_t
uid, gid_t
#if 0
if (uid == 0 && gid == 0) {
if (verbose) {
- printf("%s:%d %s authenticated connection\n",
+ qb_log(LOG_INFO, "%s:%d %s authenticated connection\n",
__FILE__, __LINE__, __func__);
}
return 1;
}
- printf("%s:%d %s() BAD user!\n", __FILE__, __LINE__, __func__);
+ qb_log(LOG_INFO, "%s:%d %s() BAD user!\n", __FILE__, __LINE__, __func__);
return 0;
#else
return 0;
@@ -64,14 +65,14 @@ static void s1_connection_created_fn(qb_ipcs_connection_t *c)
struct qb_ipcs_stats srv_stats;
qb_ipcs_stats_get(s1, &srv_stats, QB_FALSE);
- printf("\n Connection created\n > active:%d\n > closed:%d\n\n",
+ qb_log(LOG_NOTICE, "Connection created > active:%d > closed:%d",
srv_stats.active_connections,
srv_stats.closed_connections);
}
static void s1_connection_destroyed_fn(qb_ipcs_connection_t *c)
{
- printf("connection about to be freed\n");
+ qb_log(LOG_INFO, "connection about to be freed\n");
}
static int32_t s1_connection_closed_fn(qb_ipcs_connection_t *c)
@@ -83,18 +84,18 @@ static int32_t s1_connection_closed_fn(qb_ipcs_connection_t *c)
qb_ipcs_connection_stats_get(c, &stats, QB_FALSE);
- printf("\n Connection to pid:%d destroyed\n > active:%d\n >
closed:%d\n\n",
+ qb_log(LOG_INFO, "Connection to pid:%d destroyed > active:%d >
closed:%d",
stats.client_pid,
srv_stats.active_connections,
srv_stats.closed_connections);
- printf(" Requests %"PRIu64"\n", stats.requests);
- printf(" Responses %"PRIu64"\n", stats.responses);
- printf(" Events %"PRIu64"\n", stats.events);
- printf(" Send retries %"PRIu64"\n", stats.send_retries);
- printf(" Recv retries %"PRIu64"\n", stats.recv_retries);
- printf(" FC state %d\n", stats.flow_control_state);
- printf(" FC count %"PRIu64"\n\n", stats.flow_control_count);
+ qb_log(LOG_INFO, " Requests %"PRIu64"\n", stats.requests);
+ qb_log(LOG_INFO, " Responses %"PRIu64"\n", stats.responses);
+ qb_log(LOG_INFO, " Events %"PRIu64"\n", stats.events);
+ qb_log(LOG_INFO, " Send retries %"PRIu64"\n", stats.send_retries);
+ qb_log(LOG_INFO, " Recv retries %"PRIu64"\n", stats.recv_retries);
+ qb_log(LOG_INFO, " FC state %d\n", stats.flow_control_state);
+ qb_log(LOG_INFO, " FC count %"PRIu64"\n\n",
stats.flow_control_count);
return 0;
}
@@ -105,11 +106,8 @@ static int32_t s1_msg_process_fn(qb_ipcs_connection_t *c,
struct qb_ipc_response_header response;
ssize_t res;
- if (verbose > 2) {
- printf("%s:%d %s > msg:%d, size:%d\n",
- __FILE__, __LINE__, __func__,
- req_pt->id, req_pt->size);
- }
+ qb_log(LOG_TRACE, "msg:%d, size:%d",
+ req_pt->id, req_pt->size);
response.size = sizeof(struct qb_ipc_response_header);
response.id = 13;
response.error = 0;
@@ -117,49 +115,43 @@ static int32_t s1_msg_process_fn(qb_ipcs_connection_t *c,
res = qb_ipcs_response_send(c, &response,
sizeof(response));
if (res < 0) {
- perror("qb_ipcs_response_send");
+ qb_perror(LOG_ERR, "qb_ipcs_response_send");
}
}
if (events) {
res = qb_ipcs_event_send(c, &response,
sizeof(response));
if (res < 0) {
- perror("qb_ipcs_event_send");
+ qb_perror(LOG_ERR, "qb_ipcs_event_send");
}
}
return 0;
}
-static void ipc_log_fn(const char *file_name,
- int32_t file_line, int32_t severity, const char *msg)
-{
- fprintf(stderr, "%s:%d [%d] %s\n", file_name, file_line, severity, msg);
-}
-
static void sigusr1_handler(int32_t num)
{
- printf("%s(%d)\n", __func__, num);
+ qb_log(LOG_INFO, "%s(%d)\n", __func__, num);
qb_ipcs_destroy(s1);
exit(0);
}
static void show_usage(const char *name)
{
- printf("usage: \n");
- printf("%s <options>\n", name);
- printf("\n");
- printf(" options:\n");
- printf("\n");
- printf(" -n non-blocking ipc (default blocking)\n");
- printf(" -e send events back instead for responses\n");
- printf(" -v verbose\n");
- printf(" -h show this help text\n");
- printf(" -m use shared memory\n");
- printf(" -p use posix message queues\n");
- printf(" -s use sysv message queues\n");
- printf(" -u use unix sockets\n");
- printf(" -g use glib mainloop\n");
- printf("\n");
+ qb_log(LOG_INFO, "usage: \n");
+ qb_log(LOG_INFO, "%s <options>\n", name);
+ qb_log(LOG_INFO, "\n");
+ qb_log(LOG_INFO, " options:\n");
+ qb_log(LOG_INFO, "\n");
+ qb_log(LOG_INFO, " -n non-blocking ipc (default blocking)\n");
+ qb_log(LOG_INFO, " -e send events back instead for
responses\n");
+ qb_log(LOG_INFO, " -v verbose\n");
+ qb_log(LOG_INFO, " -h show this help text\n");
+ qb_log(LOG_INFO, " -m use shared memory\n");
+ qb_log(LOG_INFO, " -p use posix message queues\n");
+ qb_log(LOG_INFO, " -s use sysv message queues\n");
+ qb_log(LOG_INFO, " -u use unix sockets\n");
+ qb_log(LOG_INFO, " -g use glib mainloop\n");
+ qb_log(LOG_INFO, "\n");
}
#ifdef HAVE_GLIB
@@ -323,13 +315,17 @@ int32_t main(int32_t argc, char *argv[])
signal(SIGILL, sigusr1_handler);
signal(SIGTERM, sigusr1_handler);
- qb_util_set_log_function(ipc_log_fn);
+ qb_log_init("bms", LOG_USER, LOG_EMERG);
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
+ qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FILE, "*", LOG_INFO + verbose);
+ qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
if (!use_glib) {
bms_loop = qb_loop_create();
s1 = qb_ipcs_create("bm1", 0, ipc_type, &sh);
if (s1 == 0) {
- perror("qb_ipcs_create");
+ qb_perror(LOG_ERR, "qb_ipcs_create");
exit(1);
}
qb_ipcs_poll_handlers_set(s1, &ph);
@@ -343,7 +339,7 @@ int32_t main(int32_t argc, char *argv[])
s1 = qb_ipcs_create("bm1", 0, ipc_type, &sh);
if (s1 == 0) {
- perror("qb_ipcs_create");
+ qb_perror(LOG_ERR, "qb_ipcs_create");
exit(1);
}
qb_ipcs_poll_handlers_set(s1, &glib_ph);
@@ -351,7 +347,7 @@ int32_t main(int32_t argc, char *argv[])
g_main_loop_run(glib_loop);
#else
- printf("You don't seem to have glib-devel installed.\n");
+ qb_log(LOG_ERR, "You don't seem to have glib-devel installed.\n");
#endif
}
return EXIT_SUCCESS;
diff --git a/tests/check_log.c b/tests/check_log.c
index 58b2d4c..751072d 100644
--- a/tests/check_log.c
+++ b/tests/check_log.c
@@ -515,21 +515,14 @@ static Suite *log_suite(void)
return s;
}
-static void libqb_log_fn(const char *file_name,
- int32_t file_line, int32_t severity, const char *msg)
-{
- printf("libqb: %s:%d %s\n", file_name, file_line, msg);
-}
-
-int32_t main(void)
+int32_t
+main(void)
{
int32_t number_failed;
Suite *s = log_suite();
SRunner *sr = srunner_create(s);
- qb_util_set_log_function(libqb_log_fn);
-
srunner_run_all(sr, CK_VERBOSE);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
diff --git a/tests/loop.c b/tests/loop.c
index 2a203fc..1a6d7dd 100644
--- a/tests/loop.c
+++ b/tests/loop.c
@@ -19,51 +19,50 @@
* along with libqb. If not, see <
http://www.gnu.org/licenses/>.
*/
#include "os_base.h"
-#include <signal.h>
-
#include <sys/poll.h>
-#include <qb/qbloop.h>
-#include <qb/qbutil.h>
#include <qb/qbdefs.h>
+#include <qb/qbutil.h>
+#include <qb/qblog.h>
+#include <qb/qbloop.h>
static struct qb_loop *l;
static qb_loop_timer_handle th;
-static void job_3_9(void *data) { printf("%s\n", __func__); }
-static void job_1_2(void *data) { printf("%s\n", __func__); }
-static void job_2_4(void *data) { printf("%s\n", __func__); }
-static void job_3_5(void *data) { printf("%s\n", __func__); }
-static void job_3_6(void *data) { printf("%s\n", __func__); }
-static void job_1_1(void *data) { printf("%s\n", __func__); }
-static void job_3_7(void *data) { printf("%s\n", __func__); }
-static void job_2_3(void *data) { printf("%s\n", __func__); }
-static void job_2_8(void *data) { printf("%s\n", __func__); }
-static void job_1_9(void *data) { printf("%s\n", __func__); }
+static void job_3_9(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_1_2(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_2_4(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_3_5(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_3_6(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_1_1(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_3_7(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_2_3(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_2_8(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
+static void job_1_9(void *data) { qb_log(LOG_INFO, "%s\n", __func__); }
static void more_important_jobs(void *data)
{
- printf("%s\n", __func__);
+ qb_enter();
qb_loop_job_add(l, QB_LOOP_HIGH, NULL, job_1_2);
qb_loop_job_add(l, QB_LOOP_HIGH, NULL, job_1_9);
}
static int32_t handle_reconf_signal(int32_t sig, void *data)
{
- printf("%s(%d) \n", __func__, sig);
+ qb_log(LOG_INFO, "signal %d", sig);
return 0;
}
static int32_t handle_exit_signal(int32_t sig, void *data)
{
- printf("%s(%d) exiting ... bye\n", __func__, sig);
+ qb_log(LOG_INFO, "exiting (signal %d)... bye", sig);
qb_loop_stop(l);
return -1;
}
static void more_jobs(void *data)
{
- printf("%s\n", __func__);
+ qb_log(LOG_INFO, "%s\n", __func__);
qb_loop_timer_add(l, QB_LOOP_HIGH, 3109*QB_TIME_NS_IN_MSEC, NULL, job_1_1, &th);
qb_loop_job_add(l, QB_LOOP_LOW, NULL, job_3_7);
qb_loop_timer_add(l, QB_LOOP_LOW, 1000*QB_TIME_NS_IN_MSEC, NULL, more_important_jobs,
&th);
@@ -82,7 +81,7 @@ static int32_t read_stdin(int32_t fd, int32_t revents, void *data)
char buf[100];
ssize_t len = read(fd, buf, 100);
buf[len-1] = '\0';
- printf("typed > \"%s\"\n", buf);
+ qb_log(LOG_INFO, "typed > \"%s\"\n", buf);
if (strcmp(buf, "more") == 0) {
more_jobs(NULL);
}
@@ -90,17 +89,15 @@ static int32_t read_stdin(int32_t fd, int32_t revents, void *data)
return 0;
}
-static void libqb_log_fn(const char *file_name,
- int32_t file_line, int32_t severity, const char *msg)
-{
- printf("libqb: %s:%d %s\n", file_name, file_line, msg);
-}
-
int main(int argc, char * argv[])
{
qb_loop_signal_handle sh;
- qb_util_set_log_function(libqb_log_fn);
+ qb_log_init("loop", LOG_USER, LOG_EMERG);
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
+ qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
+ qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
l = qb_loop_create();
diff --git a/tests/rbreader.c b/tests/rbreader.c
index 3725f0f..6b5356b 100644
--- a/tests/rbreader.c
+++ b/tests/rbreader.c
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2012 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/>.
+ */
#include <stdlib.h>
#include <stdio.h>
@@ -8,6 +26,7 @@
#include <qb/qbdefs.h>
#include <qb/qbrb.h>
#include <qb/qbutil.h>
+#include <qb/qblog.h>
#define BUFFER_CHUNK_SIZE (50*50*10)
static qb_ringbuffer_t *rb = NULL;
@@ -16,17 +35,10 @@ static int keep_reading = QB_TRUE;
static void sigterm_handler(int32_t num)
{
- printf("reader: %s(%d)\n", __func__, num);
+ qb_log(LOG_INFO, "signal %d", num);
keep_reading = QB_FALSE;
}
-static void libqb_log_writer(const char *file_name,
- int32_t file_line,
- int32_t severity, const char *msg)
-{
- printf("libqb:reader: %s:%d %s\n", file_name, file_line, msg);
-}
-
int32_t main(int32_t argc, char *argv[])
{
ssize_t num_read;
@@ -34,20 +46,24 @@ int32_t main(int32_t argc, char *argv[])
signal(SIGINT, sigterm_handler);
- qb_util_set_log_function(libqb_log_writer);
+ qb_log_init("rbreader", LOG_USER, LOG_EMERG);
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
+ qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FILE, "*", LOG_INFO);
+ qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
rb = qb_rb_open("tester", BUFFER_CHUNK_SIZE * 3,
QB_RB_FLAG_SHARED_PROCESS | QB_RB_FLAG_CREATE, 0);
if (rb == NULL) {
- printf("reader: failed to create ringbuffer\n");
+ qb_perror(LOG_ERR, "failed to create ringbuffer");
return -1;
}
while (keep_reading) {
num_read = qb_rb_chunk_read(rb, buffer,
BUFFER_CHUNK_SIZE, 5500);
- if (num_read == -1) {
- printf("reader: nothing to read\n");
+ if (num_read < 0) {
+ qb_perror(LOG_ERR, "nothing to read");
}
}
qb_rb_close(rb);
diff --git a/tests/rbwriter.c b/tests/rbwriter.c
index 8985d0d..d105398 100644
--- a/tests/rbwriter.c
+++ b/tests/rbwriter.c
@@ -33,6 +33,7 @@
#include <qb/qbrb.h>
#include <qb/qbdefs.h>
#include <qb/qbutil.h>
+#include <qb/qblog.h>
static qb_ringbuffer_t *rb = NULL;
#define ITERATIONS 100000
@@ -52,18 +53,11 @@ do { \
static void sigterm_handler(int32_t num)
{
- printf("writer: %s(%d)\n", __func__, num);
+ qb_log(LOG_INFO, "writer: %s(%d)\n", __func__, num);
qb_rb_close(rb);
exit(0);
}
-static void libqb_log_writer(const char *file_name,
- int32_t file_line,
- int32_t severity, const char *msg)
-{
- printf("libqb:writer: %s:%d %s\n", file_name, file_line, msg);
-}
-
static void bm_start(void)
{
gettimeofday(&tv1, NULL);
@@ -86,8 +80,8 @@ static void bm_finish(const char *operation, int32_t size)
(((float)tv_elapsed.tv_sec) +
(((float)tv_elapsed.tv_usec) / 1000000.0))) / (1024.0 * 1024.0);
- printf("write size %d OPs/sec %9.3f ", size, ops_per_sec);
- printf("MB/sec %9.3f\n", mbs_per_sec);
+ qb_log(LOG_INFO, "write size %d OPs/sec %9.3f MB/sec %9.3f",
+ size, ops_per_sec, mbs_per_sec);
}
static void bmc_connect(void)
@@ -96,7 +90,7 @@ static void bmc_connect(void)
QB_RB_FLAG_SHARED_PROCESS, 0);
if (rb == NULL) {
- printf("writer: failed to create ringbuffer\n");
+ qb_perror(LOG_ERR, "failed to create ringbuffer");
exit(1);
}
@@ -133,11 +127,12 @@ int32_t main(int32_t argc, char *argv[])
int32_t opt;
int32_t i, j;
int32_t size;
+ int32_t verbose = 0;
while ((opt = getopt(argc, argv, options)) != -1) {
switch (opt) {
case 'v':
- qb_util_set_log_function(libqb_log_writer);
+ verbose++;
break;
case 'h':
default:
@@ -149,6 +144,12 @@ int32_t main(int32_t argc, char *argv[])
signal(SIGINT, sigterm_handler);
+ qb_log_init("rbwriter", LOG_USER, LOG_EMERG);
+ qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
+ qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
+ QB_LOG_FILTER_FILE, "*", LOG_INFO + verbose);
+ qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
+
bmc_connect();
for (j = 1; j < 49; j++) {
--
1.7.7.5