[sheepdog] [PATCH] add a print function for each log level

MORITA Kazutaka morita.kazutaka at gmail.com
Fri Aug 9 17:17:07 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

This adds the following functions.

   sd_emerg()  to log message with SDOG_EMERG
   sd_alert()  to log message with SDOG_ALERT
   sd_crit()   to log message with SDOG_CRIT
   sd_err()    to log message with SDOG_ERR
               (sd_eprintf is removed)
   sd_warn()   to log message with SDOG_WARN
   sd_notice() to log message with SDOG_NOTICE
   sd_info()   to log message with SDOG_INFO
               (sd_iprintf is removed)
   sd_debug()  to log message with SDOG_DEBUG
               (sd_dprintf is removed)

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/logger.h          |   29 +++++++----
 include/util.h            |   12 ++---
 lib/event.c               |   18 +++----
 lib/logger.c              |   33 ++++++-------
 lib/net.c                 |   66 ++++++++++++-------------
 lib/sockfd_cache.c        |   34 ++++++-------
 lib/util.c                |   28 +++++------
 lib/work.c                |   14 +++---
 sheep/cluster/corosync.c  |   51 ++++++++++---------
 sheep/cluster/local.c     |   28 +++++------
 sheep/cluster/shepherd.c  |   94 +++++++++++++++++------------------
 sheep/cluster/zookeeper.c |  121 ++++++++++++++++++++++-----------------------
 sheep/config.c            |   18 +++----
 sheep/gateway.c           |   35 +++++++------
 sheep/group.c             |  114 +++++++++++++++++++++---------------------
 sheep/http.c              |   16 +++---
 sheep/journal.c           |   35 +++++++------
 sheep/md.c                |   47 +++++++++---------
 sheep/migrate.c           |   50 +++++++++----------
 sheep/object_cache.c      |  110 ++++++++++++++++++++---------------------
 sheep/object_list_cache.c |    8 +--
 sheep/ops.c               |   54 ++++++++++----------
 sheep/plain_store.c       |   81 +++++++++++++++---------------
 sheep/recovery.c          |   86 ++++++++++++++++----------------
 sheep/request.c           |   70 +++++++++++++-------------
 sheep/sheep.c             |   51 +++++++++----------
 sheep/store.c             |   50 +++++++++----------
 sheep/trace/checker.c     |    5 +-
 sheep/trace/trace.c       |   24 ++++-----
 sheep/vdi.c               |   82 +++++++++++++++---------------
 shepherd/shepherd.c       |   83 +++++++++++++++----------------
 31 files changed, 760 insertions(+), 787 deletions(-)

diff --git a/include/logger.h b/include/logger.h
index 9253548..1589954 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -54,16 +54,27 @@ void sd_backtrace(void);
 #define	SDOG_INFO	LOG_INFO
 #define	SDOG_DEBUG	LOG_DEBUG
 
-#define sd_printf(level, fmt, args...) \
-	log_write(level, __func__, __LINE__, fmt, ##args)
-#define sd_iprintf(fmt, args...) sd_printf(SDOG_INFO, fmt, ##args)
-#define sd_eprintf(fmt, args...) sd_printf(SDOG_ERR, fmt, ##args)
-#define sd_dprintf(fmt, args...) sd_printf(SDOG_DEBUG, fmt, ##args)
+#define sd_emerg(fmt, args...) \
+	log_write(SDOG_EMERG, __func__, __LINE__, fmt, ##args)
+#define sd_alert(fmt, args...) \
+	log_write(SDOG_ALERT, __func__, __LINE__, fmt, ##args)
+#define sd_crit(fmt, args...) \
+	log_write(SDOG_CRIT, __func__, __LINE__, fmt, ##args)
+#define sd_err(fmt, args...) \
+	log_write(SDOG_ERR, __func__, __LINE__, fmt, ##args)
+#define sd_warn(fmt, args...) \
+	log_write(SDOG_WARNING, __func__, __LINE__, fmt, ##args)
+#define sd_notice(fmt, args...) \
+	log_write(SDOG_NOTICE, __func__, __LINE__, fmt, ##args)
+#define sd_info(fmt, args...) \
+	log_write(SDOG_INFO, __func__, __LINE__, fmt, ##args)
+#define sd_debug(fmt, args...) \
+	log_write(SDOG_DEBUG, __func__, __LINE__, fmt, ##args)
 
-#define panic(fmt, args...)				\
-({							\
-	sd_printf(SDOG_EMERG, "PANIC: " fmt, ##args);	\
-	abort();					\
+#define panic(fmt, args...)			\
+({						\
+	sd_emerg("PANIC: " fmt, ##args);	\
+	abort();				\
 })
 
 #endif	/* LOG_H */
diff --git a/include/util.h b/include/util.h
index e522a60..bdffd48 100644
--- a/include/util.h
+++ b/include/util.h
@@ -184,12 +184,12 @@ int atomic_create_and_write(const char *path, char *buf, size_t len,
 #endif
 
 #ifndef NDEBUG
-#define assert(expr)							\
-({									\
-	if (!(expr)) {							\
-		sd_printf(SDOG_EMERG, "Asserting `%s' failed.", #expr);	\
-		abort();						\
-	}								\
+#define assert(expr)						\
+({								\
+	if (!(expr)) {						\
+		sd_emerg("Asserting `%s' failed.", #expr);	\
+		abort();					\
+	}							\
 })
 #else
 #define assert(expr) ((void)0)
diff --git a/lib/event.c b/lib/event.c
index db00838..d949d68 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -44,7 +44,7 @@ void add_timer(struct timer *t, unsigned int mseconds)
 
 	tfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
 	if (tfd < 0) {
-		sd_eprintf("timerfd_create: %m");
+		sd_err("timerfd_create: %m");
 		return;
 	}
 
@@ -53,12 +53,12 @@ void add_timer(struct timer *t, unsigned int mseconds)
 	it.it_value.tv_nsec = (mseconds % 1000) * 1000000;
 
 	if (timerfd_settime(tfd, 0, &it, NULL) < 0) {
-		sd_eprintf("timerfd_settime: %m");
+		sd_err("timerfd_settime: %m");
 		return;
 	}
 
 	if (register_event(tfd, timer_handler, t) < 0)
-		sd_eprintf("failed to register timer fd");
+		sd_err("failed to register timer fd");
 }
 
 struct event_info {
@@ -79,7 +79,7 @@ int init_event(int nr)
 
 	efd = epoll_create(nr);
 	if (efd < 0) {
-		sd_eprintf("failed to create epoll fd");
+		sd_err("failed to create epoll fd");
 		return -1;
 	}
 	return 0;
@@ -114,7 +114,7 @@ int register_event_prio(int fd, event_handler_t h, void *data, int prio)
 
 	ret = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
 	if (ret) {
-		sd_eprintf("failed to add epoll event: %m");
+		sd_err("failed to add epoll event: %m");
 		free(ei);
 	} else
 		list_add(&ei->ei_list, &events_list);
@@ -133,7 +133,7 @@ void unregister_event(int fd)
 
 	ret = epoll_ctl(efd, EPOLL_CTL_DEL, fd, NULL);
 	if (ret)
-		sd_eprintf("failed to delete epoll event for fd %d: %m", fd);
+		sd_err("failed to delete epoll event for fd %d: %m", fd);
 
 	list_del(&ei->ei_list);
 	free(ei);
@@ -147,7 +147,7 @@ int modify_event(int fd, unsigned int new_events)
 
 	ei = lookup_event(fd);
 	if (!ei) {
-		sd_eprintf("event info for fd %d not found", fd);
+		sd_err("event info for fd %d not found", fd);
 		return 1;
 	}
 
@@ -157,7 +157,7 @@ int modify_event(int fd, unsigned int new_events)
 
 	ret = epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
 	if (ret) {
-		sd_eprintf("failed to delete epoll event for fd %d: %m", fd);
+		sd_err("failed to delete epoll event for fd %d: %m", fd);
 		return 1;
 	}
 	return 0;
@@ -193,7 +193,7 @@ refresh:
 	if (nr < 0) {
 		if (errno == EINTR)
 			return;
-		sd_eprintf("epoll_wait failed: %m");
+		sd_err("epoll_wait failed: %m");
 		exit(1);
 	} else if (nr) {
 		for (i = 0; i < nr; i++) {
diff --git a/lib/logger.c b/lib/logger.c
index a3ea11e..3a600d4 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -496,11 +496,10 @@ static bool is_sheep_dead(int signo)
 static void crash_handler(int signo)
 {
 	if (is_sheep_dead(signo))
-		sd_printf(SDOG_ERR, "sheep pid %d exited unexpectedly.",
-			  sheep_pid);
+		sd_err("sheep pid %d exited unexpectedly.", sheep_pid);
 	else {
-		sd_printf(SDOG_ERR, "logger pid %d exits unexpectedly (%s).",
-			  getpid(), strsignal(signo));
+		sd_err("logger pid %d exits unexpectedly (%s).", getpid(),
+		       strsignal(signo));
 		sd_backtrace();
 	}
 
@@ -720,7 +719,7 @@ int __sd_dump_variable(const char *var)
 	void *base_sp = FRAME_POINTER;
 
 	if (!check_gdb()) {
-		sd_dprintf("cannot find gdb");
+		sd_debug("cannot find gdb");
 		return -1;
 	}
 
@@ -732,7 +731,7 @@ int __sd_dump_variable(const char *var)
 		 path, gettid(), base_sp, var);
 	f = popen(cmd, "r");
 	if (f == NULL) {
-		sd_eprintf("failed to run gdb");
+		sd_err("failed to run gdb");
 		return -1;
 	}
 
@@ -744,15 +743,15 @@ int __sd_dump_variable(const char *var)
 	 *    <variable info>
 	 *  }
 	 */
-	sd_printf(SDOG_EMERG, "dump %s", var);
+	sd_emerg("dump %s", var);
 	while (fgets(info, sizeof(info), f) != NULL) {
 		if (info[0] == '$') {
-			sd_printf(SDOG_EMERG, "%s", info);
+			sd_emerg("%s", info);
 			break;
 		}
 	}
 	while (fgets(info, sizeof(info), f) != NULL)
-		sd_printf(SDOG_EMERG, "%s", info);
+		sd_emerg("%s", info);
 
 	pclose(f);
 	return 0;
@@ -766,7 +765,7 @@ static int dump_stack_frames(void)
 	void *base_sp = FRAME_POINTER;
 
 	if (!check_gdb()) {
-		sd_dprintf("cannot find gdb");
+		sd_debug("cannot find gdb");
 		return -1;
 	}
 
@@ -803,21 +802,21 @@ static int dump_stack_frames(void)
 				}
 				stack_no = no;
 				found = true;
-				sd_printf(SDOG_EMERG, "%s", info);
+				sd_emerg("%s", info);
 				break;
 			}
 		}
 
 		if (!found) {
-			sd_iprintf("Cannot get info from GDB");
-			sd_iprintf("Set /proc/sys/kernel/yama/ptrace_scope to"
-				   " zero if you are using Ubuntu.");
+			sd_info("Cannot get info from GDB");
+			sd_info("Set /proc/sys/kernel/yama/ptrace_scope to"
+				" zero if you are using Ubuntu.");
 			pclose(f);
 			return -1;
 		}
 
 		while (fgets(info, sizeof(info), f) != NULL)
-			sd_printf(SDOG_EMERG, "%s", info);
+			sd_emerg("%s", info);
 
 		pclose(f);
 	}
@@ -856,7 +855,7 @@ void sd_backtrace(void)
 			goto fallback_close;
 
 		if (info[0] != '?' && info[0] != '\0')
-			sd_printf(SDOG_EMERG, "%s", info);
+			sd_emerg("%s", info);
 		else
 			goto fallback_close;
 
@@ -870,7 +869,7 @@ fallback_close:
 		pclose(f);
 fallback:
 		str = backtrace_symbols(&addr, 1);
-		sd_printf(SDOG_EMERG, "%s", *str);
+		sd_emerg("%s", *str);
 		free(str);
 	}
 
diff --git a/lib/net.c b/lib/net.c
index c673ad8..0a35dd7 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -131,7 +131,7 @@ int create_listen_ports(const char *bindaddr, int port,
 
 	ret = getaddrinfo(bindaddr, servname, &hints, &res0);
 	if (ret) {
-		sd_eprintf("failed to get address info: %m");
+		sd_err("failed to get address info: %m");
 		return 1;
 	}
 
@@ -144,7 +144,7 @@ int create_listen_ports(const char *bindaddr, int port,
 		ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt,
 				 sizeof(opt));
 		if (ret)
-			sd_eprintf("failed to set SO_REUSEADDR: %m");
+			sd_err("failed to set SO_REUSEADDR: %m");
 
 		opt = 1;
 		if (res->ai_family == AF_INET6) {
@@ -158,14 +158,14 @@ int create_listen_ports(const char *bindaddr, int port,
 
 		ret = bind(fd, res->ai_addr, res->ai_addrlen);
 		if (ret) {
-			sd_eprintf("failed to bind server socket: %m");
+			sd_err("failed to bind server socket: %m");
 			close(fd);
 			continue;
 		}
 
 		ret = listen(fd, SOMAXCONN);
 		if (ret) {
-			sd_eprintf("failed to listen on server socket: %m");
+			sd_err("failed to listen on server socket: %m");
 			close(fd);
 			continue;
 		}
@@ -188,7 +188,7 @@ int create_listen_ports(const char *bindaddr, int port,
 	freeaddrinfo(res0);
 
 	if (!success)
-		sd_eprintf("failed to create a listening port");
+		sd_err("failed to create a listening port");
 
 	return !success;
 }
@@ -208,7 +208,7 @@ int connect_to(const char *name, int port)
 
 	ret = getaddrinfo(name, buf, &hints, &res0);
 	if (ret) {
-		sd_eprintf("failed to get address info: %m");
+		sd_err("failed to get address info: %m");
 		return -1;
 	}
 
@@ -226,21 +226,21 @@ int connect_to(const char *name, int port)
 		ret = setsockopt(fd, SOL_SOCKET, SO_LINGER, &linger_opt,
 				 sizeof(linger_opt));
 		if (ret) {
-			sd_eprintf("failed to set SO_LINGER: %m");
+			sd_err("failed to set SO_LINGER: %m");
 			close(fd);
 			continue;
 		}
 
 		ret = set_snd_timeout(fd);
 		if (ret) {
-			sd_eprintf("failed to set send timeout: %m");
+			sd_err("failed to set send timeout: %m");
 			close(fd);
 			break;
 		}
 
 		ret = set_rcv_timeout(fd);
 		if (ret) {
-			sd_eprintf("failed to set recv timeout: %m");
+			sd_err("failed to set recv timeout: %m");
 			close(fd);
 			break;
 		}
@@ -249,15 +249,14 @@ reconnect:
 		if (ret) {
 			if (errno == EINTR)
 				goto reconnect;
-			sd_eprintf("failed to connect to %s:%d: %m", name,
-				   port);
+			sd_err("failed to connect to %s:%d: %m", name, port);
 			close(fd);
 			continue;
 		}
 
 		ret = set_nodelay(fd);
 		if (ret) {
-			sd_eprintf("%m");
+			sd_err("%m");
 			close(fd);
 			break;
 		} else
@@ -266,7 +265,7 @@ reconnect:
 	fd = -1;
 success:
 	freeaddrinfo(res0);
-	sd_dprintf("%d, %s:%d", fd, name, port);
+	sd_debug("%d, %s:%d", fd, name, port);
 	return fd;
 }
 
@@ -277,7 +276,7 @@ int do_read(int sockfd, void *buf, int len, bool (*need_retry)(uint32_t epoch),
 reread:
 	ret = read(sockfd, buf, len);
 	if (ret == 0) {
-		sd_eprintf("connection is closed (%d bytes left)", len);
+		sd_err("connection is closed (%d bytes left)", len);
 		return 1;
 	}
 	if (ret < 0) {
@@ -293,7 +292,7 @@ reread:
 			goto reread;
 		}
 
-		sd_eprintf("failed to read from socket: %d, %m", ret);
+		sd_err("failed to read from socket: %d, %m", ret);
 		return 1;
 	}
 
@@ -338,7 +337,7 @@ rewrite:
 			goto rewrite;
 		}
 
-		sd_eprintf("failed to write to socket: %m");
+		sd_err("failed to write to socket: %m");
 		return 1;
 	}
 
@@ -376,8 +375,7 @@ int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int wlen,
 	ret = do_write(sockfd, &msg, sizeof(*hdr) + wlen, need_retry, epoch,
 		       max_count);
 	if (ret) {
-		sd_eprintf("failed to send request %x, %d: %m", hdr->opcode,
-			   wlen);
+		sd_err("failed to send request %x, %d: %m", hdr->opcode, wlen);
 		ret = -1;
 	}
 
@@ -405,7 +403,7 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
 
 	ret = do_read(sockfd, rsp, sizeof(*rsp), need_retry, epoch, max_count);
 	if (ret) {
-		sd_eprintf("failed to read a response");
+		sd_err("failed to read a response");
 		return 1;
 	}
 
@@ -415,7 +413,7 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
 	if (rlen) {
 		ret = do_read(sockfd, data, rlen, need_retry, epoch, max_count);
 		if (ret) {
-			sd_eprintf("failed to read the response data");
+			sd_err("failed to read the response data");
 			return 1;
 		}
 	}
@@ -489,12 +487,12 @@ int set_nonblocking(int fd)
 
 	ret = fcntl(fd, F_GETFL);
 	if (ret < 0) {
-		sd_eprintf("fcntl F_GETFL failed: %m");
+		sd_err("fcntl F_GETFL failed: %m");
 		close(fd);
 	} else {
 		ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
 		if (ret < 0)
-			sd_eprintf("fcntl O_NONBLOCK failed: %m");
+			sd_err("fcntl O_NONBLOCK failed: %m");
 	}
 
 	return ret;
@@ -545,22 +543,22 @@ int set_keepalive(int fd)
 	int val = 1;
 
 	if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) < 0) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		return -1;
 	}
 	val = 5;
 	if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		return -1;
 	}
 	val = 1;
 	if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		return -1;
 	}
 	val = 3;
 	if (setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		return -1;
 	}
 	return 0;
@@ -572,7 +570,7 @@ int get_local_addr(uint8_t *bytes)
 	int ret = 0;
 
 	if (getifaddrs(&ifaddr) == -1) {
-		sd_eprintf("getifaddrs failed: %m");
+		sd_err("getifaddrs failed: %m");
 		return -1;
 	}
 
@@ -592,17 +590,17 @@ int get_local_addr(uint8_t *bytes)
 			memset(bytes, 0, 12);
 			memcpy(bytes + 12, &sin->sin_addr, 4);
 			memcpy(bytes + 12, &sin->sin_addr, 4);
-			sd_eprintf("found IPv4 address");
+			sd_err("found IPv4 address");
 			goto out;
 		case AF_INET6:
 			sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
 			memcpy(bytes, &sin6->sin6_addr, 16);
-			sd_eprintf("found IPv6 address");
+			sd_err("found IPv6 address");
 			goto out;
 		}
 	}
 
-	sd_eprintf("no valid interface found");
+	sd_err("no valid interface found");
 	ret = -1;
 out:
 	freeifaddrs(ifaddr);
@@ -620,19 +618,19 @@ int create_unix_domain_socket(const char *unix_path,
 
 	fd = socket(addr.sun_family, SOCK_STREAM, 0);
 	if (fd < 0) {
-		sd_eprintf("failed to create socket, %m");
+		sd_err("failed to create socket, %m");
 		return -1;
 	}
 
 	ret = bind(fd, &addr, sizeof(addr));
 	if (ret) {
-		sd_eprintf("failed to bind socket: %m");
+		sd_err("failed to bind socket: %m");
 		goto err;
 	}
 
 	ret = listen(fd, SOMAXCONN);
 	if (ret) {
-		sd_eprintf("failed to listen on socket: %m");
+		sd_err("failed to listen on socket: %m");
 		goto err;
 	}
 
@@ -658,7 +656,7 @@ bool inetaddr_is_valid(char *addr)
 
 	af = strstr(addr, ":") ? AF_INET6 : AF_INET;
 	if (!inet_pton(af, addr, buf)) {
-		sd_eprintf("Bad address '%s'", addr);
+		sd_err("Bad address '%s'", addr);
 		return false;
 	}
 	return true;
diff --git a/lib/sockfd_cache.c b/lib/sockfd_cache.c
index f965a37..e5fc11c 100644
--- a/lib/sockfd_cache.c
+++ b/lib/sockfd_cache.c
@@ -150,7 +150,7 @@ static struct sockfd_cache_entry *sockfd_cache_grab(const struct node_id *nid,
 		char name[INET6_ADDRSTRLEN];
 
 		addr_to_str(name, sizeof(name), nid->addr, 0);
-		sd_dprintf("failed node %s:%d", name, nid->port);
+		sd_debug("failed node %s:%d", name, nid->port);
 		goto out;
 	}
 
@@ -199,12 +199,12 @@ static bool sockfd_cache_destroy(const struct node_id *nid)
 	sd_write_lock(&sockfd_cache.lock);
 	entry = sockfd_cache_search(nid);
 	if (!entry) {
-		sd_dprintf("It is already destroyed");
+		sd_debug("It is already destroyed");
 		goto false_out;
 	}
 
 	if (!slots_all_free(entry)) {
-		sd_dprintf("Some victim still holds it");
+		sd_debug("Some victim still holds it");
 		goto false_out;
 	}
 
@@ -242,7 +242,7 @@ void sockfd_cache_add_group(const struct sd_node *nodes, int nr)
 {
 	const struct sd_node *p;
 
-	sd_dprintf("%d", nr);
+	sd_debug("%d", nr);
 	sd_write_lock(&sockfd_cache.lock);
 	while (nr--) {
 		p = nodes + nr;
@@ -273,7 +273,7 @@ void sockfd_cache_add(const struct node_id *nid)
 	sd_unlock(&sockfd_cache.lock);
 	n = uatomic_add_return(&sockfd_cache.count, 1);
 	addr_to_str(name, sizeof(name), nid->addr, 0);
-	sd_dprintf("%s:%d, count %d", name, nid->port, n);
+	sd_debug("%s:%d, count %d", name, nid->port, n);
 }
 
 static uatomic_bool fds_in_grow;
@@ -287,7 +287,7 @@ static void do_grow_fds(struct work *work)
 	struct rb_node *p;
 	int old_fds_count, new_fds_count, new_size, i;
 
-	sd_dprintf("%d", fds_count);
+	sd_debug("%d", fds_count);
 	sd_write_lock(&sockfd_cache.lock);
 	old_fds_count = fds_count;
 	new_fds_count = fds_count * 2;
@@ -308,7 +308,7 @@ static void do_grow_fds(struct work *work)
 
 static void grow_fds_done(struct work *work)
 {
-	sd_dprintf("fd count has been grown into %d", fds_count);
+	sd_debug("fd count has been grown into %d", fds_count);
 	uatomic_set_false(&fds_in_grow);
 	free(work);
 }
@@ -377,16 +377,16 @@ grab:
 
 	check_idx(idx);
 	if (entry->fds[idx].fd != -1) {
-		sd_dprintf("%s:%d, idx %d", name, port, idx);
+		sd_debug("%s:%d, idx %d", name, port, idx);
 		goto out;
 	}
 
 	/* Create a new cached connection for this node */
-	sd_dprintf("create cache connection %s:%d idx %d", name, port, idx);
+	sd_debug("create cache connection %s:%d idx %d", name, port, idx);
 	fd = connect_to(name, port);
 	if (fd < 0) {
 		if (use_io) {
-			sd_eprintf("fallback to non-io connection");
+			sd_err("fallback to non-io connection");
 			fd = connect_to_addr(nid->addr, nid->port);
 			if (fd >= 0)
 				goto new;
@@ -412,7 +412,7 @@ static void sockfd_cache_put_long(const struct node_id *nid, int idx)
 	char name[INET6_ADDRSTRLEN];
 
 	addr_to_str(name, sizeof(name), addr, 0);
-	sd_dprintf("%s:%d idx %d", name, port, idx);
+	sd_debug("%s:%d idx %d", name, port, idx);
 
 	sd_read_lock(&sockfd_cache.lock);
 	entry = sockfd_cache_search(nid);
@@ -430,7 +430,7 @@ static void sockfd_cache_close(const struct node_id *nid, int idx)
 	char name[INET6_ADDRSTRLEN];
 
 	addr_to_str(name, sizeof(name), addr, 0);
-	sd_dprintf("%s:%d idx %d", name, port, idx);
+	sd_debug("%s:%d idx %d", name, port, idx);
 
 	sd_write_lock(&sockfd_cache.lock);
 	entry = sockfd_cache_search(nid);
@@ -451,7 +451,7 @@ int sockfd_init(void)
 	grow_wq = create_ordered_work_queue("sockfd_grow");
 
 	if (!grow_wq) {
-		sd_eprintf("error at creating workqueue for sockfd growth");
+		sd_err("error at creating workqueue for sockfd growth");
 		return -1;
 	}
 
@@ -484,7 +484,7 @@ struct sockfd *sockfd_cache_get(const struct node_id *nid)
 	sfd = xmalloc(sizeof(*sfd));
 	sfd->idx = -1;
 	sfd->fd = fd;
-	sd_dprintf("%d", fd);
+	sd_debug("%d", fd);
 	return sfd;
 }
 
@@ -498,7 +498,7 @@ struct sockfd *sockfd_cache_get(const struct node_id *nid)
 void sockfd_cache_put(const struct node_id *nid, struct sockfd *sfd)
 {
 	if (sfd->idx == -1) {
-		sd_dprintf("%d", sfd->fd);
+		sd_debug("%d", sfd->fd);
 		close(sfd->fd);
 		free(sfd);
 		return;
@@ -519,7 +519,7 @@ void sockfd_cache_del_node(const struct node_id *nid)
 
 	n = uatomic_sub_return(&sockfd_cache.count, 1);
 	addr_to_str(name, sizeof(name), nid->addr, 0);
-	sd_dprintf("%s:%d, count %d", name, nid->port, n);
+	sd_debug("%s:%d, count %d", name, nid->port, n);
 }
 
 /*
@@ -532,7 +532,7 @@ void sockfd_cache_del_node(const struct node_id *nid)
 void sockfd_cache_del(const struct node_id *nid, struct sockfd *sfd)
 {
 	if (sfd->idx == -1) {
-		sd_dprintf("%d", sfd->fd);
+		sd_debug("%d", sfd->fd);
 		close(sfd->fd);
 		free(sfd);
 		return;
diff --git a/lib/util.c b/lib/util.c
index 560999c..2f877c4 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -345,7 +345,7 @@ int purge_directory(char *dir_path)
 	dir = opendir(dir_path);
 	if (!dir) {
 		if (errno != ENOENT)
-			sd_eprintf("failed to open %s: %m", dir_path);
+			sd_err("failed to open %s: %m", dir_path);
 		return -errno;
 	}
 
@@ -356,7 +356,7 @@ int purge_directory(char *dir_path)
 		snprintf(path, sizeof(path), "%s/%s", dir_path, d->d_name);
 		ret = stat(path, &s);
 		if (ret) {
-			sd_eprintf("failed to stat %s: %m", path);
+			sd_err("failed to stat %s: %m", path);
 			goto out;
 		}
 		if (S_ISDIR(s.st_mode))
@@ -365,9 +365,8 @@ int purge_directory(char *dir_path)
 			ret = unlink(path);
 
 		if (ret != 0) {
-			sd_eprintf("failed to remove %s %s: %m",
-				   S_ISDIR(s.st_mode) ? "directory" : "file",
-				   path);
+			sd_err("failed to remove %s %s: %m",
+			       S_ISDIR(s.st_mode) ? "directory" : "file", path);
 			goto out;
 		}
 	}
@@ -523,10 +522,10 @@ void reraise_crash_signal(int signo, int status)
 
 	/* We won't get here normally. */
 	if (ret != 0)
-		sd_printf(SDOG_EMERG, "failed to re-raise signal %d (%s).",
+		sd_emerg("failed to re-raise signal %d (%s).",
 			  signo, strsignal(signo));
 	else
-		sd_printf(SDOG_EMERG, "default handler for the re-raised "
+		sd_emerg("default handler for the re-raised "
 			  "signal %d (%s) didn't work expectedly", signo,
 			  strsignal(signo));
 
@@ -568,30 +567,29 @@ again:
 	if (fd < 0) {
 		if (errno == EEXIST) {
 			if (force_create) {
-				sd_dprintf("clean up a temporary file %s",
-					   tmp_path);
+				sd_debug("clean up a temporary file %s",
+					 tmp_path);
 				unlink(tmp_path);
 				goto again;
 			} else
-				sd_dprintf("someone else is dealing with %s",
-					   tmp_path);
+				sd_debug("someone else is dealing with %s",
+					 tmp_path);
 		} else
-			sd_eprintf("failed to open temporal file %s, %m",
-				   tmp_path);
+			sd_err("failed to open temporal file %s, %m", tmp_path);
 		ret = -1;
 		goto end;
 	}
 
 	ret = xwrite(fd, buf, len);
 	if (ret != len) {
-		sd_eprintf("failed to write %s, %m", path);
+		sd_err("failed to write %s, %m", path);
 		ret = -1;
 		goto close_fd;
 	}
 
 	ret = rename(tmp_path, path);
 	if (ret < 0) {
-		sd_eprintf("failed to rename %s, %m", path);
+		sd_err("failed to rename %s, %m", path);
 		ret = -1;
 	}
 
diff --git a/lib/work.c b/lib/work.c
index b1febc6..305a8c0 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -144,12 +144,12 @@ static int create_worker_threads(struct worker_info *wi, size_t nr_threads)
 	while (wi->nr_threads < nr_threads) {
 		ret = pthread_create(&thread, NULL, worker_routine, wi);
 		if (ret != 0) {
-			sd_eprintf("failed to create worker thread: %m");
+			sd_err("failed to create worker thread: %m");
 			pthread_mutex_unlock(&wi->startup_lock);
 			return -1;
 		}
 		wi->nr_threads++;
-		sd_dprintf("create thread %s %zu", wi->name, wi->nr_threads);
+		sd_debug("create thread %s %zu", wi->name, wi->nr_threads);
 	}
 	pthread_mutex_unlock(&wi->startup_lock);
 
@@ -274,8 +274,8 @@ static void *worker_routine(void *arg)
 			clear_bit(tid, tid_map);
 			pthread_mutex_unlock(&wi->pending_lock);
 			pthread_detach(pthread_self());
-			sd_dprintf("destroy thread %s %d, %zu", wi->name, tid,
-				   wi->nr_threads);
+			sd_debug("destroy thread %s %d, %zu", wi->name, tid,
+				 wi->nr_threads);
 			break;
 		}
 retest:
@@ -329,19 +329,19 @@ int init_work_queue(size_t (*get_nr_nodes)(void))
 	ack_efd = eventfd(0, EFD_SEMAPHORE);
 	efd = eventfd(0, EFD_NONBLOCK);
 	if (resume_efd < 0 || ack_efd < 0 || efd < 0) {
-		sd_eprintf("failed to create event fds: %m");
+		sd_err("failed to create event fds: %m");
 		return 1;
 	}
 
 	/* trace uses this signal to suspend the worker threads */
 	if (install_sighandler(SIGUSR2, suspend, false) < 0) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		return -1;
 	}
 
 	ret = register_event(efd, worker_thread_request_done, NULL);
 	if (ret) {
-		sd_eprintf("failed to register event fd %m");
+		sd_err("failed to register event fd %m");
 		close(efd);
 		return 1;
 	}
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index d08b5e8..0bd3eb5 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -137,12 +137,12 @@ static int corosync_get_local_addr(uint8_t *addr)
 	ret = corosync_cfg_get_node_addrs(cfg_handle, this_node.nodeid, 1,
 					  &nr, &caddr);
 	if (ret != CS_OK) {
-		sd_printf(SDOG_ERR, "failed to get node addresses (%d)", ret);
+		sd_err("failed to get node addresses (%d)", ret);
 		return -1;
 	}
 
 	if (!nr) {
-		sd_printf(SDOG_ERR, "no node addresses found");
+		sd_err("no node addresses found");
 		return -1;
 	}
 
@@ -154,7 +154,7 @@ static int corosync_get_local_addr(uint8_t *addr)
 		memset(addr, 0, 16);
 		memcpy(addr + 12, saddr, 4);
 	} else {
-		sd_printf(SDOG_ERR, "unknown protocol %d", ss->ss_family);
+		sd_err("unknown protocol %d", ss->ss_family);
 		return -1;
 	}
 
@@ -190,11 +190,11 @@ retry:
 	case CS_OK:
 		break;
 	case CS_ERR_TRY_AGAIN:
-		sd_dprintf("failed to send message: retrying");
+		sd_debug("failed to send message: retrying");
 		sleep(1);
 		goto retry;
 	default:
-		sd_eprintf("failed to send message (%d)", ret);
+		sd_err("failed to send message (%d)", ret);
 		return SD_RES_CLUSTER_ERROR;
 	}
 	return SD_RES_SUCCESS;
@@ -368,7 +368,7 @@ static void __corosync_dispatch(void)
 		 * number of alive nodes correctly, we postpone
 		 * processsing events if there are incoming ones.
 		 */
-		sd_dprintf("wait for a next dispatch event");
+		sd_debug("wait for a next dispatch event");
 		return;
 	}
 
@@ -445,7 +445,7 @@ static void cdrv_cpg_deliver(cpg_handle_t handle,
 	struct corosync_event *cevent;
 	struct corosync_message *cmsg = msg;
 
-	sd_dprintf("%d", cmsg->type);
+	sd_debug("%d", cmsg->type);
 
 	switch (cmsg->type) {
 	case COROSYNC_MSG_TYPE_JOIN:
@@ -549,8 +549,8 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 	struct cpg_node left_sheep[SD_MAX_NODES];
 	bool promote = true;
 
-	sd_dprintf("mem:%zu, joined:%zu, left:%zu", member_list_entries,
-		   joined_list_entries, left_list_entries);
+	sd_debug("mem:%zu, joined:%zu, left:%zu", member_list_entries,
+		 joined_list_entries, left_list_entries);
 
 	/* check network partition */
 	if (left_list_entries) {
@@ -619,8 +619,8 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 			cevent = find_event(COROSYNC_EVENT_TYPE_JOIN,
 					    &member_sheep[i]);
 			if (!cevent) {
-				sd_dprintf("Not promoting because member is "
-					   "not in our event list.");
+				sd_debug("Not promoting because member is not "
+					 "in our event list.");
 				promote = false;
 				break;
 			}
@@ -647,14 +647,14 @@ retry:
 	case CS_OK:
 		break;
 	case CS_ERR_TRY_AGAIN:
-		sd_dprintf("failed to join the sheepdog group: retrying");
+		sd_debug("failed to join the sheepdog group: retrying");
 		sleep(1);
 		goto retry;
 	case CS_ERR_SECURITY:
-		sd_eprintf("permission denied to join the sheepdog group");
+		sd_err("permission denied to join the sheepdog group");
 		return -1;
 	default:
-		sd_eprintf("failed to join the sheepdog group (%d)", ret);
+		sd_err("failed to join the sheepdog group (%d)", ret);
 		return -1;
 	}
 
@@ -695,13 +695,13 @@ static void corosync_handler(int listen_fd, int events, void *data)
 	int ret;
 
 	if (events & EPOLLHUP) {
-		sd_eprintf("corosync driver received EPOLLHUP event, exiting.");
+		sd_err("corosync driver received EPOLLHUP event, exiting.");
 		goto out;
 	}
 
 	ret = cpg_dispatch(cpg_handle, CS_DISPATCH_ALL);
 	if (ret != CS_OK) {
-		sd_eprintf("cpg_dispatch returned %d", ret);
+		sd_err("cpg_dispatch returned %d", ret);
 		goto out;
 	}
 
@@ -728,28 +728,28 @@ again:
 		break;
 	case CS_ERR_TRY_AGAIN:
 		if (retry_cnt++ == CPG_INIT_RETRY_CNT) {
-			sd_eprintf("failed to initialize cpg (%d) - "
-				   "is corosync running?", ret);
+			sd_err("failed to initialize cpg (%d) - "
+			       "is corosync running?", ret);
 			return -1;
 		}
-		sd_dprintf("retry cpg_initialize");
+		sd_debug("retry cpg_initialize");
 		usleep(200000);
 		goto again;
 	default:
-		sd_eprintf("failed to initialize cpg (%d) - "
-			   "is corosync running?", ret);
+		sd_err("failed to initialize cpg (%d) - is corosync running?",
+		       ret);
 		return -1;
 	}
 
 	ret = corosync_cfg_initialize(&cfg_handle, NULL);
 	if (ret != CS_OK) {
-		sd_printf(SDOG_ERR, "failed to initialize cfg (%d)", ret);
+		sd_err("failed to initialize cfg (%d)", ret);
 		return -1;
 	}
 
 	ret = corosync_cfg_local_get(cfg_handle, &nodeid);
 	if (ret != CS_OK) {
-		sd_printf(SDOG_ERR, "failed to get node id (%d)", ret);
+		sd_err("failed to get node id (%d)", ret);
 		return -1;
 	}
 
@@ -758,14 +758,13 @@ again:
 
 	ret = cpg_fd_get(cpg_handle, &cpg_fd);
 	if (ret != CS_OK) {
-		sd_eprintf("failed to get cpg file descriptor (%d)", ret);
+		sd_err("failed to get cpg file descriptor (%d)", ret);
 		return -1;
 	}
 
 	ret = register_event(cpg_fd, corosync_handler, NULL);
 	if (ret) {
-		sd_eprintf("failed to register corosync event handler (%d)",
-			   ret);
+		sd_err("failed to register corosync event handler (%d)", ret);
 		return -1;
 	}
 
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index 9135ab7..4350ca2 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -183,7 +183,7 @@ static void shm_queue_notify(void)
 	nr = get_nodes(lnodes);
 
 	for (i = 0; i < nr; i++) {
-		sd_dprintf("send signal to %s", lnode_to_str(lnodes + i));
+		sd_debug("send signal to %s", lnode_to_str(lnodes + i));
 		kill(lnodes[i].pid, SIGUSR1);
 	}
 }
@@ -281,9 +281,9 @@ static int add_event(enum local_event_type type, struct local_node *lnode,
 		abort();
 	}
 
-	sd_dprintf("type = %d, sender = %s", ev.type, lnode_to_str(&ev.sender));
+	sd_debug("type = %d, sender = %s", ev.type, lnode_to_str(&ev.sender));
 	for (int i = 0; i < ev.nr_lnodes; i++)
-		sd_dprintf("%d: %s", i, lnode_to_str(ev.lnodes + i));
+		sd_debug("%d: %s", i, lnode_to_str(ev.lnodes + i));
 
 	shm_queue_push(&ev);
 
@@ -390,14 +390,12 @@ static bool local_process_event(void)
 	if (!ev)
 		return false;
 
-	sd_dprintf("type = %d, sender = %s", ev->type,
-		   lnode_to_str(&ev->sender));
-	sd_dprintf("callbacked = %d, removed = %d", ev->callbacked,
-		   ev->removed);
+	sd_debug("type = %d, sender = %s", ev->type, lnode_to_str(&ev->sender));
+	sd_debug("callbacked = %d, removed = %d", ev->callbacked, ev->removed);
 
 	nr_nodes = 0;
 	for (i = 0; i < ev->nr_lnodes; i++) {
-		sd_dprintf("%d: %s", i, lnode_to_str(ev->lnodes + i));
+		sd_debug("%d: %s", i, lnode_to_str(ev->lnodes + i));
 		if (!ev->lnodes[i].gateway)
 			nodes[nr_nodes++] = ev->lnodes[i].node;
 	}
@@ -416,7 +414,7 @@ static bool local_process_event(void)
 		case EVENT_JOIN:
 			break;
 		case EVENT_ACCEPT:
-			sd_dprintf("join Sheepdog");
+			sd_debug("join Sheepdog");
 			joined = true;
 			break;
 		default:
@@ -442,8 +440,8 @@ static bool local_process_event(void)
 		break;
 	case EVENT_LEAVE:
 		if (ev->sender.gateway) {
-			sd_dprintf("gateway %s left sheepdog",
-				   lnode_to_str(&ev->sender));
+			sd_debug("gateway %s left sheepdog",
+				 lnode_to_str(&ev->sender));
 			break;
 		}
 		/* fall through */
@@ -476,12 +474,12 @@ static void local_handler(int listen_fd, int events, void *data)
 	int ret;
 
 	if (events & EPOLLHUP) {
-		sd_eprintf("local driver received EPOLLHUP event, exiting.");
+		sd_err("local driver received EPOLLHUP event, exiting.");
 		log_close();
 		exit(1);
 	}
 
-	sd_dprintf("read siginfo");
+	sd_debug("read siginfo");
 
 	ret = read(sigfd, &siginfo, sizeof(siginfo));
 	if (ret != sizeof(siginfo))
@@ -524,7 +522,7 @@ static int local_init(const char *option)
 
 	sigfd = signalfd(-1, &mask, SFD_NONBLOCK);
 	if (sigfd < 0) {
-		sd_eprintf("failed to create a signal fd: %m");
+		sd_err("failed to create a signal fd: %m");
 		return -1;
 	}
 
@@ -532,7 +530,7 @@ static int local_init(const char *option)
 
 	ret = register_event(sigfd, local_handler, NULL);
 	if (ret) {
-		sd_eprintf("failed to register local event handler (%d)", ret);
+		sd_err("failed to register local event handler (%d)", ret);
 		return -1;
 	}
 
diff --git a/sheep/cluster/shepherd.c b/sheep/cluster/shepherd.c
index c1753e0..6a2d205 100644
--- a/sheep/cluster/shepherd.c
+++ b/sheep/cluster/shepherd.c
@@ -62,7 +62,7 @@ static int do_shepherd_join(void)
 
 	ret = writev2(sph_comm_fd, &msg, msg_join, msg_join_len);
 	if (sizeof(msg) + msg_join_len != ret) {
-		sd_eprintf("do_shepherd_join() failed, %m");
+		sd_err("do_shepherd_join() failed, %m");
 		free(msg_join);
 
 		return -1;
@@ -78,7 +78,7 @@ static void read_msg(struct sph_msg *rcv)
 
 	ret = xread(sph_comm_fd, rcv, sizeof(*rcv));
 	if (ret != sizeof(*rcv)) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		exit(1);
 	}
 }
@@ -93,7 +93,7 @@ retry:
 	read_msg(&rcv);
 
 	if (rcv.type == SPH_SRV_MSG_JOIN_RETRY) {
-		sd_iprintf("join request is rejected, retrying");
+		sd_info("join request is rejected, retrying");
 
 		do_shepherd_join();
 		goto retry;
@@ -105,7 +105,7 @@ retry:
 		join = xzalloc(join_len);
 		ret = xread(sph_comm_fd, join, join_len);
 		if (ret != join_len) {
-			sd_eprintf("xread() failed: %m");
+			sd_err("xread() failed: %m");
 			exit(1);
 		}
 
@@ -121,7 +121,7 @@ retry:
 
 		ret = writev2(sph_comm_fd, &snd, join, join_len);
 		if (sizeof(snd) + join_len != ret) {
-			sd_eprintf("writev2() failed: %m");
+			sd_err("writev2() failed: %m");
 			exit(1);
 		}
 
@@ -131,8 +131,8 @@ retry:
 	}
 
 	if (rcv.type != SPH_SRV_MSG_JOIN_REPLY) {
-		sd_eprintf("unexpected message from shepherd, "
-			"received message: %s", sph_srv_msg_to_str(rcv.type));
+		sd_err("unexpected message from shepherd, received message: %s",
+		       sph_srv_msg_to_str(rcv.type));
 
 		/*
 		 * In this case, the state of this sheep in shepherd must be
@@ -145,11 +145,11 @@ retry:
 	join_reply = xzalloc(rcv.body_len);
 	ret = xread(sph_comm_fd, join_reply, rcv.body_len);
 	if (ret != rcv.body_len) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		exit(1);
 	}
 
-	sd_iprintf("join reply arrived, nr_nodes: %d", join_reply->nr_nodes);
+	sd_info("join reply arrived, nr_nodes: %d", join_reply->nr_nodes);
 
 	memcpy(nodes, join_reply->nodes,
 	       join_reply->nr_nodes * sizeof(struct sd_node));
@@ -160,7 +160,7 @@ retry:
 
 	free(join_reply);
 
-	sd_iprintf("shepherd_join() succeed");
+	sd_info("shepherd_join() succeed");
 	state = STATE_JOINED;
 }
 
@@ -203,11 +203,11 @@ static bool sph_process_event(void)
 		return false;
 
 	if (nonblock) {
-		sd_dprintf("processing nonblock event");
+		sd_debug("processing nonblock event");
 
 		sd_notify_handler(&ev->sender, ev->msg, ev->msg_len);
 	} else {
-		sd_dprintf("processing block event");
+		sd_debug("processing block event");
 
 		ev->callbacked = sd_block_handler(&ev->sender);
 		return false;
@@ -226,8 +226,8 @@ static void push_sph_event(bool nonblock, struct sd_node *sender,
 {
 	struct sph_event *ev;
 
-	sd_dprintf("push_sph_event() called, pushing %sblocking event",
-		nonblock ? "non" : "");
+	sd_debug("push_sph_event() called, pushing %sblocking event",
+		 nonblock ? "non" : "");
 
 	ev = xzalloc(sizeof(*ev));
 
@@ -272,7 +272,7 @@ static void remove_one_block_event(void)
 
 	eventfd_xwrite(sph_event_fd, 1);
 
-	sd_dprintf("unblock a blocking event");
+	sd_debug("unblock a blocking event");
 }
 
 static void sph_event_handler(int fd, int events, void *data)
@@ -292,7 +292,7 @@ static void msg_new_node(struct sph_msg *rcv)
 	join = xzalloc(rcv->body_len);
 	ret = xread(sph_comm_fd, join, rcv->body_len);
 	if (ret != rcv->body_len) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		exit(1);
 	}
 
@@ -311,7 +311,7 @@ static void msg_new_node(struct sph_msg *rcv)
 
 	ret = writev2(sph_comm_fd, &snd, join, rcv->body_len);
 	if (sizeof(snd) + rcv->body_len != ret) {
-		sd_eprintf("writev() failed: %m");
+		sd_err("writev() failed: %m");
 		exit(1);
 	}
 	free(join);
@@ -325,7 +325,7 @@ static void msg_new_node_finish(struct sph_msg *rcv)
 	join_node_finish = xzalloc(rcv->body_len);
 	ret = xread(sph_comm_fd, join_node_finish, rcv->body_len);
 	if (ret != rcv->body_len) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		exit(1);
 	}
 
@@ -333,8 +333,7 @@ static void msg_new_node_finish(struct sph_msg *rcv)
 	       join_node_finish->nr_nodes * sizeof(struct sd_node));
 	nr_nodes = join_node_finish->nr_nodes;
 
-	sd_iprintf("new node: %s",
-		   node_to_str(&join_node_finish->new_node));
+	sd_info("new node: %s", node_to_str(&join_node_finish->new_node));
 
 	/* FIXME: member change events must be ordered with nonblocked events */
 	sd_accept_handler(&join_node_finish->new_node, nodes, nr_nodes,
@@ -351,7 +350,7 @@ static void msg_notify_forward(struct sph_msg *rcv)
 	notify_forward = xzalloc(rcv->body_len);
 	ret = xread(sph_comm_fd, notify_forward, rcv->body_len);
 	if (ret != rcv->body_len) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		exit(1);
 	}
 
@@ -372,7 +371,7 @@ static void msg_block_forward(struct sph_msg *rcv)
 
 	ret = xread(sph_comm_fd, &sender, sizeof(sender));
 	if (ret != sizeof(sender)) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		exit(1);
 	}
 
@@ -386,35 +385,34 @@ static void do_leave_sheep(void)
 
 	ret = xread(sph_comm_fd, &sender, sizeof(sender));
 	if (ret != sizeof(sender)) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		exit(1);
 	}
 
-	sd_iprintf("removing node: %s", node_to_str(&sender));
+	sd_info("removing node: %s", node_to_str(&sender));
 
 	if (xlremove(&sender, nodes, &nr_nodes, node_cmp))
 		goto removed;
 
-	sd_iprintf("leave message from unknown node: %s",
-		node_to_str(&sender));
+	sd_info("leave message from unknown node: %s", node_to_str(&sender));
 	return;
 
 removed:
-	sd_dprintf("calling sd_leave_handler(), sender: %s",
-		node_to_str(&sender));
+	sd_debug("calling sd_leave_handler(), sender: %s",
+		 node_to_str(&sender));
 	/* FIXME: member change events must be ordered with nonblocked events */
 	sd_leave_handler(&sender, nodes, nr_nodes);
 }
 
 static void msg_remove(struct sph_msg *rcv)
 {
-	sd_iprintf("sudden leaving of sheep is caused");
+	sd_info("sudden leaving of sheep is caused");
 	do_leave_sheep();
 }
 
 static void msg_leave_forward(struct sph_msg *rcv)
 {
-	sd_iprintf("intuitive leaving of sheep is caused");
+	sd_info("intuitive leaving of sheep is caused");
 	do_leave_sheep();
 }
 
@@ -430,8 +428,8 @@ static void (*msg_handlers[])(struct sph_msg *) = {
 static void interpret_msg(struct sph_msg *rcv)
 {
 	if (!(0 <= rcv->type && rcv->type < ARRAY_SIZE(msg_handlers))) {
-		sd_eprintf("invalid message from shepherd: %s",
-			sph_srv_msg_to_str(rcv->type));
+		sd_err("invalid message from shepherd: %s",
+		       sph_srv_msg_to_str(rcv->type));
 		exit(1);
 	}
 
@@ -465,7 +463,7 @@ static void shepherd_comm_handler(int fd, int events, void *data)
 	if (events & EPOLLIN)
 		read_msg_from_shepherd();
 	else if (events & EPOLLHUP || events & EPOLLERR) {
-		sd_eprintf("connection to shepherd caused an error: %m");
+		sd_err("connection to shepherd caused an error: %m");
 		exit(1);
 	}
 }
@@ -476,20 +474,20 @@ static int shepherd_init(const char *option)
 	char *copied, *s_addr, *s_port, *saveptr;
 
 	if (!option) {
-		sd_eprintf("shepherd cluster driver requires at least IP"
-			" address of shepherd as an option");
+		sd_err("shepherd cluster driver requires at least IP"
+		       " address of shepherd as an option");
 		exit(1);
 	}
 
 	copied = strdup(option);
 	if (!copied) {
-		sd_eprintf("strdup() failed: %m");
+		sd_err("strdup() failed: %m");
 		exit(1);
 	}
 
 	s_addr = strtok_r(copied, ":", &saveptr);
 	if (!s_addr) {
-		sd_eprintf("strdup() failed: %m");
+		sd_err("strdup() failed: %m");
 		exit(1);
 	}
 
@@ -499,8 +497,7 @@ static int shepherd_init(const char *option)
 		port = strtol(s_port, &p, 10);
 
 		if (*p != '\0') {
-			sd_eprintf("invalid option for host and port: %s",
-				option);
+			sd_err("invalid option for host and port: %s", option);
 			exit(1);
 		}
 	} else
@@ -508,15 +505,15 @@ static int shepherd_init(const char *option)
 
 	sph_comm_fd = connect_to(s_addr, port);
 	if (sph_comm_fd == -1) {
-		sd_eprintf("cannot connect to shepherd,"
-			" is shepherd running? errno: %m");
+		sd_err("cannot connect to shepherd,"
+		       " is shepherd running? errno: %m");
 		return -1;
 	}
 
 	sph_event_fd = eventfd(0, EFD_NONBLOCK);
 	ret = register_event(sph_event_fd, sph_event_handler, NULL);
 	if (ret) {
-		sd_eprintf("register_event() failed: %m");
+		sd_err("register_event() failed: %m");
 		exit(1);
 	}
 
@@ -537,8 +534,7 @@ static int shepherd_join(const struct sd_node *myself,
 	kept_opaque_len = opaque_len;
 	this_node = *myself;
 
-	sd_dprintf("shepherd_join() called, myself is %s",
-		node_to_str(myself));
+	sd_debug("shepherd_join() called, myself is %s", node_to_str(myself));
 
 	ret = do_shepherd_join();
 
@@ -560,11 +556,11 @@ static int shepherd_leave(void)
 
 	ret = xwrite(sph_comm_fd, &msg, sizeof(msg));
 	if (ret != sizeof(msg)) {
-		sd_iprintf("xwrite() failed: %m");
+		sd_info("xwrite() failed: %m");
 		exit(1);
 	}
 
-	sd_dprintf("shepherd_leave() is completed");
+	sd_debug("shepherd_leave() is completed");
 
 	return 0;
 }
@@ -584,12 +580,12 @@ static int do_shepherd_notify(bool unblock, void *msg, size_t msg_len)
 
 	ret = writev2(sph_comm_fd, &snd, notify, snd.body_len);
 	if (sizeof(snd) + snd.body_len != ret) {
-		sd_eprintf("writev() failed: %m");
+		sd_err("writev() failed: %m");
 		exit(1);
 	}
 	free(notify);
 
-	sd_iprintf("do_shepherd_notify() is completed");
+	sd_info("do_shepherd_notify() is completed");
 
 	return 0;
 }
@@ -610,7 +606,7 @@ static int shepherd_block(void)
 
 	ret = xwrite(sph_comm_fd, &msg, sizeof(msg));
 	if (ret != sizeof(msg)) {
-		sd_eprintf("xwrite() failed: %m");
+		sd_err("xwrite() failed: %m");
 		exit(1);
 	}
 
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index d28b287..5088968 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -151,7 +151,7 @@ static struct zk_node this_node;
 	case ZSESSIONEXPIRED:						\
 	case ZOPERATIONTIMEOUT:						\
 	case ZCONNECTIONLOSS:						\
-		sd_eprintf("failed, path:%s, %s", path, zerror(rc));	\
+		sd_err("failed, path:%s, %s", path, zerror(rc));	\
 	case ZOK:							\
 		break;							\
 	case ZNOCHILDRENFOREPHEMERALS:					\
@@ -160,8 +160,8 @@ static struct zk_node this_node;
 		 * always non-ephemeral, this could happen only when	\
 		 * sheep joins a cluster in an incompatible version.	\
 		 */							\
-		sd_eprintf("incompatible version of sheep %s",		\
-			   PACKAGE_VERSION);				\
+		sd_err("incompatible version of sheep %s",		\
+		       PACKAGE_VERSION);				\
 	default:							\
 		panic("failed, path:%s, %s", path, zerror(rc));		\
 	}
@@ -169,8 +169,8 @@ static struct zk_node this_node;
 	do {								\
 		int __rc = stmt;					\
 		if (__rc != ZOK) {					\
-			sd_eprintf("failed, " fmt ", %s",		\
-				   ##__VA_ARGS__, zerror(__rc));	\
+			sd_err("failed, " fmt ", %s",			\
+			       ##__VA_ARGS__, zerror(__rc));		\
 			return __rc;					\
 		}							\
 	} while (0)
@@ -178,8 +178,8 @@ static struct zk_node this_node;
 	do {								\
 		int __rc = stmt;					\
 		if (__rc != ZOK) {					\
-			sd_eprintf("failed, " fmt ", %s",		\
-				   ##__VA_ARGS__, zerror(__rc));	\
+			sd_err("failed, " fmt ", %s",			\
+			       ##__VA_ARGS__, zerror(__rc));		\
 			return;						\
 		}							\
 	} while (0)
@@ -315,7 +315,7 @@ static int zk_queue_peek(bool *peek)
 		*peek = false;
 		return ZOK;
 	default:
-		sd_eprintf("failed, %s", zerror(rc));
+		sd_err("failed, %s", zerror(rc));
 		return rc;
 	}
 }
@@ -335,18 +335,18 @@ static int zk_find_seq_node(uint64_t id, char *seq_path, int seq_path_len,
 		switch (rc) {
 		case ZOK:
 			if (ev.id == id) {
-				sd_dprintf("id %"PRIx64" is found in %s", id,
-					   seq_path);
+				sd_debug("id %" PRIx64 " is found in %s", id,
+					 seq_path);
 				*found = true;
 				return ZOK;
 			}
 			break;
 		case ZNONODE:
-			sd_dprintf("id %"PRIx64" is not found", id);
+			sd_debug("id %"PRIx64" is not found", id);
 			*found = false;
 			return ZOK;
 		default:
-			sd_eprintf("failed, %s", zerror(rc));
+			sd_err("failed, %s", zerror(rc));
 			return rc;
 		}
 	}
@@ -377,7 +377,7 @@ again:
 		}
 		/* fall through */
 	default:
-		sd_eprintf("failed, path:%s, %s", path, zerror(rc));
+		sd_err("failed, path:%s, %s", path, zerror(rc));
 		return rc;
 	}
 	if (first_push) {
@@ -389,8 +389,8 @@ again:
 		first_push = false;
 	}
 
-	sd_dprintf("create path:%s, queue_pos:%010"PRId32", len:%d",
-		   buf, queue_pos, len);
+	sd_debug("create path:%s, queue_pos:%010" PRId32 ", len:%d", buf,
+		 queue_pos, len);
 	return ZOK;
 }
 
@@ -415,8 +415,8 @@ static int push_join_response(struct zk_event *ev)
 	snprintf(path, sizeof(path), QUEUE_ZNODE "/%010"PRId32, queue_pos);
 
 	RETURN_IF_ERROR(zk_set_data(path, (char *)ev, len, -1), "");
-	sd_dprintf("update path:%s, queue_pos:%010"PRId32", len:%d",
-		   path, queue_pos, len);
+	sd_debug("update path:%s, queue_pos:%010" PRId32 ", len:%d", path,
+		 queue_pos, len);
 	return ZOK;
 }
 
@@ -429,8 +429,8 @@ static int zk_queue_pop_advance(struct zk_event *ev)
 	snprintf(path, sizeof(path), QUEUE_ZNODE "/%010"PRId32, queue_pos);
 
 	RETURN_IF_ERROR(zk_get_data(path, ev, &len), "path %s", path);
-	sd_dprintf("%s, type:%d, len:%d, pos:%"PRId32, path, ev->type,
-		   len, queue_pos);
+	sd_debug("%s, type:%d, len:%d, pos:%" PRId32, path, ev->type, len,
+		 queue_pos);
 	queue_pos++;
 	return ZOK;
 }
@@ -490,7 +490,7 @@ static inline void build_node_list(void)
 		zk = rb_entry(n, struct zk_node, rb);
 		sd_nodes[nr_sd_nodes++] = zk->node;
 	}
-	sd_dprintf("nr_sd_nodes:%zu", nr_sd_nodes);
+	sd_debug("nr_sd_nodes:%zu", nr_sd_nodes);
 }
 
 static int zk_queue_init(void)
@@ -530,7 +530,7 @@ static int add_event(enum zk_event_type type, struct zk_node *znode, void *buf,
 	if (rc == ZOK)
 		return SD_RES_SUCCESS;
 	else {
-		sd_eprintf("failed, type: %d, %s", type, zerror(rc));
+		sd_err("failed, type: %d, %s", type, zerror(rc));
 		return SD_RES_CLUSTER_ERROR;
 	}
 }
@@ -552,7 +552,7 @@ static void zk_watcher(zhandle_t *zh, int type, int state, const char *path,
 	}
 
 /* CREATED_EVENT 1, DELETED_EVENT 2, CHANGED_EVENT 3, CHILD_EVENT 4 */
-	sd_dprintf("path:%s, type:%d", path, type);
+	sd_debug("path:%s, type:%d", path, type);
 	if (type == ZOO_CREATED_EVENT || type == ZOO_CHANGED_EVENT) {
 		ret = sscanf(path, MEMBER_ZNODE "/%s", str);
 		if (ret == 1)
@@ -632,7 +632,7 @@ static int zk_get_least_seq(const char *parent, char *least_seq_path,
 		case ZNONODE:
 			break;
 		default:
-			sd_eprintf("failed, %s", zerror(rc));
+			sd_err("failed, %s", zerror(rc));
 			return rc;
 		}
 	}
@@ -661,12 +661,12 @@ static int zk_find_master(int *master_seq, char *master_name)
 			case ZOK:
 				return ZOK;
 			case ZNONODE:
-				sd_iprintf("detect master leave, "
-					   "start to compete master");
+				sd_info("detect master leave, "
+					"start to compete master");
 				(*master_seq)++;
 				break;
 			default:
-				sd_eprintf("failed, %s", zerror(rc));
+				sd_err("failed, %s", zerror(rc));
 				return rc;
 			}
 		}
@@ -692,7 +692,7 @@ static int zk_verify_last_sheep_join(int seq, int *last_sheep)
 		case ZOK:
 			break;
 		default:
-			sd_eprintf("failed, %s", zerror(rc));
+			sd_err("failed, %s", zerror(rc));
 			return rc;
 		}
 
@@ -708,7 +708,7 @@ static int zk_verify_last_sheep_join(int seq, int *last_sheep)
 			(*last_sheep)++;
 			break;
 		default:
-			sd_eprintf("failed, %s", zerror(rc));
+			sd_err("failed, %s", zerror(rc));
 			return rc;
 		}
 	}
@@ -736,7 +736,7 @@ static void zk_compete_master(void)
 		goto out_unlock;
 
 	if (!joined) {
-		sd_dprintf("start to compete master for the first time");
+		sd_debug("start to compete master for the first time");
 		do {
 			if (uatomic_is_true(&stop))
 				goto out_unlock;
@@ -751,7 +751,7 @@ static void zk_compete_master(void)
 		if (rc != ZOK)
 			goto out_unlock;
 
-		sd_dprintf("my compete path: %s", my_compete_path);
+		sd_debug("my compete path: %s", my_compete_path);
 		sscanf(my_compete_path, MASTER_ZNONE "/%"PRId32,
 		       &my_seq);
 	}
@@ -762,7 +762,7 @@ static void zk_compete_master(void)
 	if (!strcmp(master_name, node_to_str(&this_node.node)))
 		goto success;
 	else if (joined) {
-		sd_dprintf("lost");
+		sd_debug("lost");
 		goto out_unlock;
 	} else {
 		if (zk_verify_last_sheep_join(my_seq,
@@ -774,13 +774,13 @@ static void zk_compete_master(void)
 			master_seq = my_seq;
 			goto success;
 		} else {
-			sd_dprintf("lost");
+			sd_debug("lost");
 			goto out_unlock;
 		}
 	}
 success:
 	uatomic_set_true(&is_master);
-	sd_dprintf("success");
+	sd_debug("success");
 out_unlock:
 	sd_unlock(&zk_compete_master_lock);
 }
@@ -796,7 +796,7 @@ static int zk_join(const struct sd_node *myself,
 	snprintf(path, sizeof(path), MEMBER_ZNODE "/%s", node_to_str(myself));
 	rc = zk_node_exists(path);
 	if (rc == ZOK) {
-		sd_eprintf("Previous zookeeper session exist, shoot myself.");
+		sd_err("Previous zookeeper session exist, shoot myself.");
 		exit(1);
 	}
 
@@ -810,7 +810,7 @@ static int zk_leave(void)
 {
 	char path[PATH_MAX];
 
-	sd_iprintf("leaving from cluster");
+	sd_info("leaving from cluster");
 	uatomic_set_true(&stop);
 
 	snprintf(path, sizeof(path), MEMBER_ZNODE"/%s",
@@ -837,7 +837,7 @@ static int zk_unblock(void *msg, size_t msg_len)
 
 static void zk_handle_join(struct zk_event *ev)
 {
-	sd_dprintf("sender: %s", node_to_str(&ev->sender.node));
+	sd_debug("sender: %s", node_to_str(&ev->sender.node));
 	if (!uatomic_is_true(&is_master)) {
 		/* Let's await master acking the join-request */
 		queue_pos--;
@@ -847,7 +847,7 @@ static void zk_handle_join(struct zk_event *ev)
 	sd_join_handler(&ev->sender.node, sd_nodes, nr_sd_nodes, ev->buf);
 	push_join_response(ev);
 
-	sd_dprintf("I'm the master now");
+	sd_debug("I'm the master now");
 }
 
 static void watch_all_nodes(void)
@@ -868,7 +868,7 @@ static void init_node_list(struct zk_event *ev)
 	size_t node_nr = ev->nr_nodes;
 	int i;
 
-	sd_dprintf("%zu", node_nr);
+	sd_debug("%zu", node_nr);
 	for (i = 0; i < node_nr; i++) {
 		struct zk_node zk;
 		mempcpy(&zk.node, p, sizeof(struct sd_node));
@@ -884,18 +884,18 @@ static void zk_handle_accept(struct zk_event *ev)
 	char path[MAX_NODE_STR_LEN];
 	int rc;
 
-	sd_dprintf("ACCEPT");
+	sd_debug("ACCEPT");
 	if (node_eq(&ev->sender.node, &this_node.node))
 		/* newly joined node */
 		init_node_list(ev);
 
-	sd_dprintf("%s", node_to_str(&ev->sender.node));
+	sd_debug("%s", node_to_str(&ev->sender.node));
 
 	snprintf(path, sizeof(path), MEMBER_ZNODE"/%s",
 		 node_to_str(&ev->sender.node));
 	if (node_eq(&ev->sender.node, &this_node.node)) {
 		joined = true;
-		sd_dprintf("create path:%s", path);
+		sd_debug("create path:%s", path);
 		rc = zk_create_node(path,
 				    (char *)zoo_client_id(zhandle),
 				    sizeof(clientid_t),
@@ -939,8 +939,8 @@ static void zk_handle_leave(struct zk_event *ev)
 	struct zk_node *n = zk_tree_search(&ev->sender.node.nid);
 
 	if (!n) {
-		sd_dprintf("can't find this leave node:%s, ignore it.",
-			   node_to_str(&ev->sender.node));
+		sd_debug("can't find this leave node:%s, ignore it.",
+			 node_to_str(&ev->sender.node));
 		return;
 	}
 	block_event_list_del(n);
@@ -953,7 +953,7 @@ static void zk_handle_block(struct zk_event *ev)
 {
 	struct zk_node *block = xzalloc(sizeof(*block));
 
-	sd_dprintf("BLOCK");
+	sd_debug("BLOCK");
 	block->node = ev->sender.node;
 	list_add_tail(&block->list, &zk_block_list);
 	block = list_first_entry(&zk_block_list, typeof(*block), list);
@@ -965,7 +965,7 @@ static void zk_handle_unblock(struct zk_event *ev)
 {
 	struct zk_node *block;
 
-	sd_dprintf("UNBLOCK");
+	sd_debug("UNBLOCK");
 	if (list_empty(&zk_block_list))
 		return;
 	block = list_first_entry(&zk_block_list, typeof(*block), list);
@@ -977,7 +977,7 @@ static void zk_handle_unblock(struct zk_event *ev)
 
 static void zk_handle_notify(struct zk_event *ev)
 {
-	sd_dprintf("NOTIFY");
+	sd_debug("NOTIFY");
 	sd_notify_handler(&ev->sender.node, ev->buf, ev->buf_len);
 }
 
@@ -986,7 +986,7 @@ static void zk_handle_update_node(struct zk_event *ev)
 	struct zk_node *t;
 	struct sd_node *snode = &ev->sender.node;
 
-	sd_dprintf("%s", node_to_str(snode));
+	sd_debug("%s", node_to_str(snode));
 
 	if (node_eq(snode, &this_node.node))
 		this_node.node = *snode;
@@ -1032,7 +1032,7 @@ static inline void handle_session_expire(void)
 	memset(sd_nodes, 0, sizeof(struct sd_node) * SD_MAX_NODES);
 
 	while (sd_reconnect_handler()) {
-		sd_eprintf("failed to reconnect. sleep and retry...");
+		sd_err("failed to reconnect. sleep and retry...");
 		sleep(1);
 	}
 }
@@ -1042,10 +1042,9 @@ static void zk_event_handler(int listen_fd, int events, void *data)
 	struct zk_event ev;
 	bool peek;
 
-	sd_dprintf("%d, %d", events, queue_pos);
+	sd_debug("%d, %d", events, queue_pos);
 	if (events & EPOLLHUP) {
-		sd_eprintf("zookeeper driver received EPOLLHUP event,"
-			   " exiting.");
+		sd_err("zookeeper driver received EPOLLHUP event, exiting.");
 		log_close();
 		exit(1);
 	}
@@ -1053,9 +1052,9 @@ static void zk_event_handler(int listen_fd, int events, void *data)
 	eventfd_xread(efd);
 
 	if (zoo_state(zhandle) == ZOO_EXPIRED_SESSION_STATE) {
-		sd_eprintf("detect a session timeout. reconnecting...");
+		sd_err("detect a session timeout. reconnecting...");
 		handle_session_expire();
-		sd_iprintf("reconnected");
+		sd_info("reconnected");
 		eventfd_xwrite(efd, 1);
 		return;
 	}
@@ -1094,25 +1093,24 @@ static int zk_init(const char *option)
 	int ret, timeout = SESSION_TIMEOUT;
 
 	if (!option) {
-		sd_eprintf("You must specify zookeeper servers.");
+		sd_err("You must specify zookeeper servers.");
 		return -1;
 	}
 
 	hosts = strtok((char *)option, "=");
 	if ((to = strtok(NULL, "="))) {
 		if (sscanf(to, "%u", &timeout) != 1) {
-			sd_eprintf("Invalid paramter for timeout");
+			sd_err("Invalid paramter for timeout");
 			return -1;
 		}
 		p = strstr(hosts, "timeout");
 		*--p = '\0';
 	}
-	sd_dprintf("version %d.%d.%d, address %s, timeout %d",
-		   ZOO_MAJOR_VERSION, ZOO_MINOR_VERSION, ZOO_PATCH_VERSION,
-		   hosts, timeout);
+	sd_debug("version %d.%d.%d, address %s, timeout %d", ZOO_MAJOR_VERSION,
+		 ZOO_MINOR_VERSION, ZOO_PATCH_VERSION, hosts, timeout);
 	zhandle = zookeeper_init(hosts, zk_watcher, timeout, NULL, NULL, 0);
 	if (!zhandle) {
-		sd_eprintf("failed to connect to zk server %s", option);
+		sd_err("failed to connect to zk server %s", option);
 		return -1;
 	}
 
@@ -1123,14 +1121,13 @@ static int zk_init(const char *option)
 
 	efd = eventfd(0, EFD_NONBLOCK);
 	if (efd < 0) {
-		sd_eprintf("failed to create an event fd: %m");
+		sd_err("failed to create an event fd: %m");
 		return -1;
 	}
 
 	ret = register_event(efd, zk_event_handler, NULL);
 	if (ret) {
-		sd_eprintf("failed to register zookeeper event handler (%d)",
-			   ret);
+		sd_err("failed to register zookeeper event handler (%d)", ret);
 		return -1;
 	}
 
diff --git a/sheep/config.c b/sheep/config.c
index e6fc35d..67198c0 100644
--- a/sheep/config.c
+++ b/sheep/config.c
@@ -35,7 +35,7 @@ static int write_config(void)
 	ret = atomic_create_and_write(config_path, (char *)&config,
 				      sizeof(config), true);
 	if (ret < 0) {
-		sd_eprintf("atomic_create_and_write() failed");
+		sd_err("atomic_create_and_write() failed");
 		return SD_RES_EIO;
 	}
 
@@ -53,7 +53,7 @@ static void check_tmp_config(void)
 	if (!ret || ret != ENOENT)
 		return;
 
-	sd_iprintf("removed temporal config file");
+	sd_info("removed temporal config file");
 }
 
 int init_config_file(void)
@@ -65,7 +65,7 @@ int init_config_file(void)
 	fd = open(config_path, O_RDONLY);
 	if (fd < 0) {
 		if (errno != ENOENT) {
-			sd_eprintf("failed to read config file, %m");
+			sd_err("failed to read config file, %m");
 			return -1;
 		}
 		goto create;
@@ -77,13 +77,13 @@ int init_config_file(void)
 		goto create;
 	}
 	if (ret < 0) {
-		sd_eprintf("failed to read config file, %m");
+		sd_err("failed to read config file, %m");
 		goto out;
 	}
 
 	if (config.version != SD_FORMAT_VERSION) {
-		sd_eprintf("This sheep version is not compatible with"
-			   " the existing data layout, %d", config.version);
+		sd_err("This sheep version is not compatible with"
+		       " the existing data layout, %d", config.version);
 		if (sys->upgrade) {
 			/* upgrade sheep store */
 			ret = sd_migrate_store(config.version, SD_FORMAT_VERSION);
@@ -91,8 +91,8 @@ int init_config_file(void)
 				/* reload config file */
 				ret = xpread(fd, &config, sizeof(config), 0);
 				if (ret != sizeof(config)) {
-					sd_eprintf("failed to reload config"
-						   " file, %m");
+					sd_err("failed to reload config file,"
+					       " %m");
 					ret = -1;
 				} else
 					ret = 0;
@@ -100,7 +100,7 @@ int init_config_file(void)
 			goto out;
 		}
 
-		sd_eprintf("use '-u' option to upgrade sheep store");
+		sd_err("use '-u' option to upgrade sheep store");
 		ret = -1;
 		goto out;
 	}
diff --git a/sheep/gateway.c b/sheep/gateway.c
index 7cb6169..af7ba2a 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -44,7 +44,7 @@ int gateway_read_obj(struct request *req)
 	nr_copies = get_req_copy_number(req);
 
 	if (nr_copies == 0) {
-		sd_dprintf("there is no living nodes");
+		sd_debug("there is no living nodes");
 		return SD_RES_HALT;
 	}
 
@@ -58,8 +58,8 @@ int gateway_read_obj(struct request *req)
 		if (ret == SD_RES_SUCCESS)
 			goto out;
 
-		sd_eprintf("local read %"PRIx64" failed, %s", oid,
-			   sd_strerror(ret));
+		sd_err("local read %"PRIx64" failed, %s", oid,
+		       sd_strerror(ret));
 		break;
 	}
 
@@ -112,7 +112,7 @@ struct write_info {
 
 static inline void write_info_update(struct write_info *wi, int pos)
 {
-	sd_dprintf("%d, %d", wi->nr_sent, pos);
+	sd_debug("%d, %d", wi->nr_sent, pos);
 	wi->nr_sent--;
 	memmove(wi->ent + pos, wi->ent + pos + 1,
 		sizeof(struct write_info_entry) * (wi->nr_sent - pos));
@@ -172,10 +172,9 @@ again:
 		 */
 		if (sheep_need_retry(req->rq.epoch) && repeat) {
 			repeat--;
-			sd_printf(SDOG_WARNING,
-				  "poll timeout %d, disks of some nodes or"
-				   " network is busy. Going to poll-wait again",
-				   wi->nr_sent);
+			sd_warn("poll timeout %d, disks of some nodes or "
+				"network is busy. Going to poll-wait again",
+				wi->nr_sent);
 			goto again;
 		}
 
@@ -193,7 +192,7 @@ again:
 			break;
 	if (i < nr_sent) {
 		int re = pi.pfds[i].revents;
-		sd_dprintf("%d, revents %x", i, re);
+		sd_debug("%d, revents %x", i, re);
 		if (re & (POLLERR | POLLHUP | POLLNVAL)) {
 			err_ret = SD_RES_NETWORK_ERROR;
 			finish_one_write_err(wi, i);
@@ -201,7 +200,7 @@ again:
 		}
 		if (do_read(pi.pfds[i].fd, rsp, sizeof(*rsp), sheep_need_retry,
 			    req->rq.epoch, MAX_RETRY_COUNT)) {
-			sd_eprintf("remote node might have gone away");
+			sd_err("remote node might have gone away");
 			err_ret = SD_RES_NETWORK_ERROR;
 			finish_one_write_err(wi, i);
 			goto finish_write;
@@ -209,8 +208,8 @@ again:
 
 		ret = rsp->result;
 		if (ret != SD_RES_SUCCESS) {
-			sd_eprintf("fail %"PRIx64", %s", req->rq.obj.oid,
-				   sd_strerror(ret));
+			sd_err("fail %"PRIx64", %s", req->rq.obj.oid,
+			       sd_strerror(ret));
 			err_ret = ret;
 		}
 		finish_one_write(wi, i);
@@ -265,7 +264,7 @@ static int gateway_forward_request(struct request *req)
 	struct sd_req hdr;
 	const struct sd_node *target_nodes[SD_MAX_NODES];
 
-	sd_dprintf("%"PRIx64, oid);
+	sd_debug("%"PRIx64, oid);
 
 	gateway_init_fwd_hdr(&hdr, &req->rq);
 	op = get_sd_op(hdr.opcode);
@@ -275,7 +274,7 @@ static int gateway_forward_request(struct request *req)
 	write_info_init(&wi, nr_to_send);
 
 	if (nr_to_send == 0) {
-		sd_dprintf("there is no living nodes");
+		sd_debug("there is no living nodes");
 		return SD_RES_HALT;
 	}
 
@@ -301,7 +300,7 @@ static int gateway_forward_request(struct request *req)
 		if (ret) {
 			sockfd_cache_del_node(nid);
 			err_ret = SD_RES_NETWORK_ERROR;
-			sd_dprintf("fail %d", ret);
+			sd_debug("fail %d", ret);
 			break;
 		}
 		write_info_advance(&wi, nid, sfd);
@@ -312,13 +311,13 @@ static int gateway_forward_request(struct request *req)
 		ret = sheep_do_op_work(op, req);
 
 		if (ret != SD_RES_SUCCESS) {
-			sd_eprintf("fail to write local %"PRIx64", %s", oid,
-				   sd_strerror(ret));
+			sd_err("fail to write local %"PRIx64", %s", oid,
+			       sd_strerror(ret));
 			err_ret = ret;
 		}
 	}
 
-	sd_dprintf("nr_sent %d, err %x", wi.nr_sent, err_ret);
+	sd_debug("nr_sent %d, err %x", wi.nr_sent, err_ret);
 	if (wi.nr_sent > 0) {
 		ret = wait_forward_request(&wi, req);
 		if (ret != SD_RES_SUCCESS)
diff --git a/sheep/group.c b/sheep/group.c
index 8f223f5..9bc8072 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -204,7 +204,7 @@ static void cluster_op_done(struct work *work)
 	if (req->status == REQUEST_DROPPED)
 		goto drop;
 
-	sd_dprintf("%s (%p)", op_name(req->op), req);
+	sd_debug("%s (%p)", op_name(req->op), req);
 
 	msg = prepare_cluster_msg(req, &size);
 
@@ -215,8 +215,7 @@ static void cluster_op_done(struct work *work)
 		 * unblock the event.
 		 * FIXME: handle it gracefully.
 		 */
-		sd_printf(SDOG_EMERG, "Failed to unblock, %s, exiting.",
-			  sd_strerror(ret));
+		sd_emerg("Failed to unblock, %s, exiting.", sd_strerror(ret));
 		exit(1);
 	}
 
@@ -271,13 +270,13 @@ main_fn bool sd_block_handler(const struct sd_node *sender)
 main_fn void queue_cluster_request(struct request *req)
 {
 	int ret;
-	sd_dprintf("%s (%p)", op_name(req->op), req);
+	sd_debug("%s (%p)", op_name(req->op), req);
 
 	if (has_process_work(req->op)) {
 		ret = sys->cdrv->block();
 		if (ret != SD_RES_SUCCESS) {
-			sd_eprintf("failed to broadcast block to cluster, %s",
-				   sd_strerror(ret));
+			sd_err("failed to broadcast block to cluster, %s",
+			       sd_strerror(ret));
 			goto error;
 		}
 		list_add_tail(&req->pending_list,
@@ -291,8 +290,8 @@ main_fn void queue_cluster_request(struct request *req)
 
 		ret = sys->cdrv->notify(msg, size);
 		if (ret != SD_RES_SUCCESS) {
-			sd_eprintf("failed to broadcast notify to cluster, %s",
-				   sd_strerror(ret));
+			sd_err("failed to broadcast notify to cluster, %s",
+			       sd_strerror(ret));
 			goto error;
 		}
 
@@ -363,8 +362,8 @@ static bool cluster_ctime_check(const struct cluster_info *cinfo)
 		return true;
 
 	if (cinfo->ctime != sys->cinfo.ctime) {
-		sd_eprintf("joining node ctime doesn't match: %" PRIu64 " vs %"
-			   PRIu64, cinfo->ctime, sys->cinfo.ctime);
+		sd_err("joining node ctime doesn't match: %" PRIu64 " vs %"
+		       PRIu64, cinfo->ctime, sys->cinfo.ctime);
 		return false;
 	}
 
@@ -387,13 +386,13 @@ static bool enough_nodes_gathered(struct cluster_info *cinfo,
 
 		n = xlfind(key, nodes, nr_nodes, node_cmp);
 		if (n == NULL && !node_eq(key, joining)) {
-			sd_dprintf("%s doesn't join yet", node_to_str(key));
+			sd_debug("%s doesn't join yet", node_to_str(key));
 			return false;
 		}
 	}
 
-	sd_dprintf("all the nodes are gathered, %d, %zd", cinfo->nr_nodes,
-		   nr_nodes);
+	sd_debug("all the nodes are gathered, %d, %zd", cinfo->nr_nodes,
+		 nr_nodes);
 	return true;
 }
 
@@ -403,13 +402,13 @@ static enum sd_status cluster_wait_check(const struct sd_node *joining,
 					 struct cluster_info *cinfo)
 {
 	if (!cluster_ctime_check(cinfo)) {
-		sd_dprintf("joining node is invalid");
+		sd_debug("joining node is invalid");
 		return sys->cinfo.status;
 	}
 
 	if (cinfo->epoch > sys->cinfo.epoch) {
-		sd_dprintf("joining node has a larger epoch, %" PRIu32 ", %"
-			   PRIu32, cinfo->epoch, sys->cinfo.epoch);
+		sd_debug("joining node has a larger epoch, %" PRIu32 ", %"
+			 PRIu32, cinfo->epoch, sys->cinfo.epoch);
 		sys->cinfo = *cinfo;
 	}
 
@@ -462,12 +461,12 @@ static void do_get_vdis(struct work *work)
 	int i, ret;
 
 	if (!node_is_local(&w->joined)) {
-		sd_dprintf("try to get vdi bitmap from %s",
-			   node_to_str(&w->joined));
+		sd_debug("try to get vdi bitmap from %s",
+			 node_to_str(&w->joined));
 		ret = get_vdis_from(&w->joined);
 		if (ret != SD_RES_SUCCESS)
-			sd_printf(SDOG_ALERT, "failed to get vdi bitmap from "
-				  "%s", node_to_str(&w->joined));
+			sd_alert("failed to get vdi bitmap from %s",
+				 node_to_str(&w->joined));
 		return;
 	}
 
@@ -476,13 +475,13 @@ static void do_get_vdis(struct work *work)
 		if (node_is_local(&w->members[i]))
 			continue;
 
-		sd_dprintf("try to get vdi bitmap from %s",
-			   node_to_str(&w->members[i]));
+		sd_debug("try to get vdi bitmap from %s",
+			 node_to_str(&w->members[i]));
 		ret = get_vdis_from(&w->members[i]);
 		if (ret != SD_RES_SUCCESS) {
 			/* try to read from another node */
-			sd_printf(SDOG_ALERT, "failed to get vdi bitmap from "
-				  "%s", node_to_str(&w->members[i]));
+			sd_alert("failed to get vdi bitmap from %s",
+				 node_to_str(&w->members[i]));
 			continue;
 		}
 
@@ -592,14 +591,14 @@ static void get_vdis(const struct sd_node *nodes, size_t nr_nodes,
 
 void wait_get_vdis_done(void)
 {
-	sd_dprintf("waiting for vdi list");
+	sd_debug("waiting for vdi list");
 
 	pthread_mutex_lock(&wait_vdis_lock);
 	while (!is_vdi_list_ready)
 		pthread_cond_wait(&wait_vdis_cond, &wait_vdis_lock);
 	pthread_mutex_unlock(&wait_vdis_lock);
 
-	sd_dprintf("vdi list ready");
+	sd_debug("vdi list ready");
 }
 
 void recalculate_vnodes(struct sd_node *nodes, int nr_nodes)
@@ -623,9 +622,8 @@ void recalculate_vnodes(struct sd_node *nodes, int nr_nodes)
 	for (i = 0; i < nr_nodes; i++) {
 		factor = (float)nodes[i].space / (float)avg_size;
 		nodes[i].nr_vnodes = rintf(SD_DEFAULT_VNODES * factor);
-		sd_dprintf("node %d has %d vnodes, free space %" PRIu64,
-			   nodes[i].nid.port, nodes[i].nr_vnodes,
-			   nodes[i].space);
+		sd_debug("node %d has %d vnodes, free space %" PRIu64,
+			 nodes[i].nid.port, nodes[i].nr_vnodes, nodes[i].space);
 	}
 }
 
@@ -636,7 +634,7 @@ static void update_cluster_info(const struct cluster_info *cinfo,
 {
 	struct vnode_info *old_vnode_info;
 
-	sd_dprintf("status = %d, epoch = %d", cinfo->status, cinfo->epoch);
+	sd_debug("status = %d, epoch = %d", cinfo->status, cinfo->epoch);
 
 	if (!sys->gateway_only)
 		setup_backend_store(cinfo);
@@ -693,8 +691,8 @@ main_fn void sd_notify_handler(const struct sd_node *sender, void *data,
 	int ret = msg->rsp.result;
 	struct request *req = NULL;
 
-	sd_dprintf("op %s, size: %zu, from: %s", op_name(op), data_len,
-		   node_to_str(sender));
+	sd_debug("op %s, size: %zu, from: %s", op_name(op), data_len,
+		 node_to_str(sender));
 
 	if (node_is_local(sender)) {
 		if (has_process_work(op))
@@ -747,11 +745,11 @@ main_fn bool sd_join_handler(const struct sd_node *joining,
 	 * not 0, the joining node has to wait for another node to accept it.
 	 */
 	if (nr_nodes > 0 && node_is_local(joining)) {
-		sd_dprintf("wait for another node to accept this node");
+		sd_debug("wait for another node to accept this node");
 		return false;
 	}
 
-	sd_dprintf("check %s, %d", node_to_str(joining), sys->cinfo.status);
+	sd_debug("check %s, %d", node_to_str(joining), sys->cinfo.status);
 
 	if (sys->cinfo.status == SD_STATUS_WAIT)
 		status = cluster_wait_check(joining, nodes, nr_nodes, cinfo);
@@ -762,16 +760,16 @@ main_fn bool sd_join_handler(const struct sd_node *joining,
 	cinfo->status = status;
 	cinfo->proto_ver = SD_SHEEP_PROTO_VER;
 
-	sd_dprintf("%s: cluster_status = 0x%x",
-		   addr_to_str(str, sizeof(str), joining->nid.addr,
-			       joining->nid.port), cinfo->status);
+	sd_debug("%s: cluster_status = 0x%x",
+		 addr_to_str(str, sizeof(str), joining->nid.addr,
+			     joining->nid.port), cinfo->status);
 
 	return true;
 }
 
 static int send_join_request(struct sd_node *ent)
 {
-	sd_printf(SDOG_INFO, "%s", node_to_str(&sys->this_node));
+	sd_info("%s", node_to_str(&sys->this_node));
 
 	return sys->cdrv->join(ent, &sys->cinfo, sizeof(sys->cinfo));
 }
@@ -791,8 +789,8 @@ static void requeue_cluster_request(void)
 		 * driver. We manually call sd_notify_handler to finish
 		 * the request.
 		 */
-		sd_dprintf("finish pending notify request, op: %s",
-			   op_name(req->op));
+		sd_debug("finish pending notify request, op: %s",
+			 op_name(req->op));
 		msg = prepare_cluster_msg(req, &size);
 		sd_notify_handler(&sys->this_node, msg, size);
 		free(msg);
@@ -803,8 +801,8 @@ static void requeue_cluster_request(void)
 		switch (req->status) {
 		case REQUEST_INIT:
 			/* this request has never been executed, re-queue it */
-			sd_dprintf("requeue a block request, op: %s",
-				   op_name(req->op));
+			sd_debug("requeue a block request, op: %s",
+				 op_name(req->op));
 			list_del(&req->pending_list);
 			queue_cluster_request(req);
 			break;
@@ -817,8 +815,8 @@ static void requeue_cluster_request(void)
 			 * timeout. Mark it as dropped to stop cluster_op_done()
 			 * from calling ->unblock.
 			 */
-			sd_dprintf("drop pending block request, op: %s",
-				   op_name(req->op));
+			sd_debug("drop pending block request, op: %s",
+				 op_name(req->op));
 			req->status = REQUEST_DROPPED;
 			break;
 		case REQUEST_DONE:
@@ -829,8 +827,8 @@ static void requeue_cluster_request(void)
 			 * driver. We manually call sd_notify_handler to finish
 			 * the request.
 			 */
-			sd_dprintf("finish pending block request, op: %s",
-				   op_name(req->op));
+			sd_debug("finish pending block request, op: %s",
+				 op_name(req->op));
 			msg = prepare_cluster_msg(req, &size);
 			sd_notify_handler(&sys->this_node, msg, size);
 			free(msg);
@@ -855,8 +853,8 @@ main_fn int sd_reconnect_handler(void)
 static bool cluster_join_check(const struct cluster_info *cinfo)
 {
 	if (cinfo->proto_ver != SD_SHEEP_PROTO_VER) {
-		sd_eprintf("invalid protocol version: %d, %d",
-			   cinfo->proto_ver, SD_SHEEP_PROTO_VER);
+		sd_err("invalid protocol version: %d, %d", cinfo->proto_ver,
+		       SD_SHEEP_PROTO_VER);
 		return false;
 	}
 
@@ -866,7 +864,7 @@ static bool cluster_join_check(const struct cluster_info *cinfo)
 	if (cinfo->epoch == sys->cinfo.epoch &&
 	    memcmp(cinfo->nodes, sys->cinfo.nodes,
 		   sizeof(cinfo->nodes[0]) * cinfo->nr_nodes) != 0) {
-		sd_printf(SDOG_ALERT, "epoch log entries does not match");
+		sd_alert("epoch log entries does not match");
 		return false;
 	}
 
@@ -881,15 +879,15 @@ main_fn void sd_accept_handler(const struct sd_node *joined,
 	const struct cluster_info *cinfo = opaque;
 
 	if (!cluster_join_check(cinfo)) {
-		sd_eprintf("failed to join Sheepdog");
+		sd_err("failed to join Sheepdog");
 		exit(1);
 	}
 
 	sys->cinfo = *cinfo;
 
-	sd_dprintf("join %s", node_to_str(joined));
+	sd_debug("join %s", node_to_str(joined));
 	for (i = 0; i < nr_members; i++)
-		sd_dprintf("[%x] %s", i, node_to_str(members + i));
+		sd_debug("[%x] %s", i, node_to_str(members + i));
 
 	if (sys->cinfo.status == SD_STATUS_SHUTDOWN)
 		return;
@@ -898,7 +896,7 @@ main_fn void sd_accept_handler(const struct sd_node *joined,
 
 	if (node_is_local(joined))
 		/* this output is used for testing */
-		sd_printf(SDOG_DEBUG, "join Sheepdog cluster");
+		sd_debug("join Sheepdog cluster");
 }
 
 main_fn void sd_leave_handler(const struct sd_node *left,
@@ -908,9 +906,9 @@ main_fn void sd_leave_handler(const struct sd_node *left,
 	struct vnode_info *old_vnode_info;
 	int i, ret;
 
-	sd_dprintf("leave %s", node_to_str(left));
+	sd_debug("leave %s", node_to_str(left));
 	for (i = 0; i < nr_members; i++)
-		sd_dprintf("[%x] %s", i, node_to_str(members + i));
+		sd_debug("[%x] %s", i, node_to_str(members + i));
 
 	if (sys->cinfo.status == SD_STATUS_SHUTDOWN)
 		return;
@@ -970,8 +968,8 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
 
 	if (!sys->cdrv) {
 		sys->cdrv = find_cdrv(DEFAULT_CLUSTER_DRIVER);
-		sd_dprintf("use %s cluster driver as default",
-			   DEFAULT_CLUSTER_DRIVER);
+		sd_debug("use %s cluster driver as default",
+			 DEFAULT_CLUSTER_DRIVER);
 	}
 
 	ret = sys->cdrv->init(sys->cdrv_option);
@@ -993,7 +991,7 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
 		sys->this_node.zone = b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24;
 	} else
 		sys->this_node.zone = zone;
-	sd_dprintf("zone id = %u", sys->this_node.zone);
+	sd_debug("zone id = %u", sys->this_node.zone);
 
 	sys->this_node.space = sys->disk_space;
 
diff --git a/sheep/http.c b/sheep/http.c
index 204ee20..88c66e4 100644
--- a/sheep/http.c
+++ b/sheep/http.c
@@ -78,10 +78,10 @@ static inline int http_request_error(struct http_request *req)
 	if (ret == 0) {
 		return OK;
 	} else if (ret < 0) {
-		sd_eprintf("failed, FCGI error %d", ret);
+		sd_err("failed, FCGI error %d", ret);
 		return INTERNAL_SERVER_ERROR;
 	} else {
-		sd_eprintf("failed, %s", strerror(ret));
+		sd_err("failed, %s", strerror(ret));
 		return INTERNAL_SERVER_ERROR;
 	}
 }
@@ -158,7 +158,7 @@ static int http_init_request(struct http_request *req)
 	int ret;
 
 	for (int i = 0; (p = req->fcgx.envp[i]); ++i)
-		sd_dprintf("%s", p);
+		sd_debug("%s", p);
 
 	ret = request_init_operation(req);
 	if (ret != OK)
@@ -268,7 +268,7 @@ static void *http_main_loop(void *ignored)
 
 		ret = FCGX_Accept_r(&req->fcgx);
 		if (ret < 0) {
-			sd_eprintf("accept failed, %d, %d", http_sockfd, ret);
+			sd_err("accept failed, %d, %d", http_sockfd, ret);
 			goto out;
 		}
 		ret = http_init_request(req);
@@ -282,7 +282,7 @@ static void *http_main_loop(void *ignored)
 out:
 	err = pthread_detach(pthread_self());
 	if (err)
-		sd_eprintf("%s", strerror(err));
+		sd_err("%s", strerror(err));
 	pthread_exit(NULL);
 }
 
@@ -300,13 +300,13 @@ int http_init(const char *address)
 #define LISTEN_QUEUE_DEPTH 1024 /* No rationale */
 	http_sockfd = FCGX_OpenSocket(address, LISTEN_QUEUE_DEPTH);
 	if (http_sockfd < 0) {
-		sd_eprintf("open socket failed, address %s", address);
+		sd_err("open socket failed, address %s", address);
 		return -1;
 	}
-	sd_iprintf("http service listen at %s", address);
+	sd_info("http service listen at %s", address);
 	err = pthread_create(&t, NULL, http_main_loop, NULL);
 	if (err) {
-		sd_eprintf("%s", strerror(err));
+		sd_err("%s", strerror(err));
 		return -1;
 	}
 	return 0;
diff --git a/sheep/journal.c b/sheep/journal.c
index 990ef94..2beaba9 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -67,11 +67,11 @@ static int create_journal_file(const char *root, const char *name)
 	snprintf(path, sizeof(path), "%s/%s", root, name);
 	fd = open(path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 	if (fd < 0) {
-		sd_eprintf("open %s %m", name);
+		sd_err("open %s %m", name);
 		return -1;
 	}
 	if (prealloc(fd, jfile_size) < 0) {
-		sd_eprintf("prealloc %s %m", name);
+		sd_err("prealloc %s %m", name);
 		return -1;
 	}
 
@@ -92,19 +92,19 @@ static int get_old_new_jfile(const char *p, int *old, int *new)
 		if (errno == ENOENT)
 			return 0;
 
-		sd_eprintf("open1 %m");
+		sd_err("open1 %m");
 		return -1;
 	}
 	snprintf(path, sizeof(path), "%s/%s", p, jfile_name[1]);
 	fd2 = open(path, flags);
 	if (fd2 < 0) {
-		sd_eprintf("open2 %m");
+		sd_err("open2 %m");
 		close(fd1);
 		return -1;
 	}
 
 	if (fstat(fd1, &st1) < 0 || fstat(fd2, &st2) < 0) {
-		sd_eprintf("stat %m");
+		sd_err("stat %m");
 		goto out;
 	}
 
@@ -146,21 +146,21 @@ static int replay_journal_entry(struct journal_descriptor *jd)
 		 md_get_object_path(jd->oid), jd->oid);
 
 	if (jd->flag == JF_REMOVE_OBJ) {
-		sd_iprintf("%s (remove)", path);
+		sd_info("%s (remove)", path);
 		unlink(path);
 
 		return 0;
 	}
 
-	sd_iprintf("%s, size %"PRIu64", off %"PRIu64", %d",
-		   path, jd->size, jd->offset, jd->create);
+	sd_info("%s, size %" PRIu64 ", off %" PRIu64 ", %d", path, jd->size,
+		jd->offset, jd->create);
 
 	if (jd->create)
 		flags |= O_CREAT;
 
 	fd = open(path, flags, sd_def_fmode);
 	if (fd < 0) {
-		sd_eprintf("open %m");
+		sd_err("open %m");
 		return -1;
 	}
 
@@ -174,8 +174,7 @@ static int replay_journal_entry(struct journal_descriptor *jd)
 	memcpy(buf, p, jd->size);
 	size = xpwrite(fd, buf, jd->size, jd->offset);
 	if (size != jd->size) {
-		sd_eprintf("write %zd, size %" PRIu64 ", errno %m", size,
-			   jd->size);
+		sd_err("write %zd, size %" PRIu64 ", errno %m", size, jd->size);
 		ret = -1;
 		goto out;
 	}
@@ -193,7 +192,7 @@ static int do_recover(int fd)
 	struct stat st;
 
 	if (fstat(fd, &st) < 0) {
-		sd_eprintf("fstat %m");
+		sd_err("fstat %m");
 		return -1;
 	}
 
@@ -210,7 +209,7 @@ static int do_recover(int fd)
 	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	close(fd);
 	if (map == MAP_FAILED) {
-		sd_eprintf("%m");
+		sd_err("%m");
 		return -1;
 	}
 
@@ -291,12 +290,12 @@ void clean_journal_file(const char *p)
 	snprintf(path, sizeof(path), "%s/%s", p, jfile_name[0]);
 	ret = unlink(path);
 	if (ret < 0)
-		sd_eprintf("unlink(%s): %m", path);
+		sd_err("unlink(%s): %m", path);
 
 	snprintf(path, sizeof(path), "%s/%s", p, jfile_name[1]);
 	ret = unlink(path);
 	if (ret < 0)
-		sd_eprintf("unlink(%s): %m", path);
+		sd_err("unlink(%s): %m", path);
 }
 
 static inline bool jfile_enough_space(size_t size)
@@ -340,8 +339,8 @@ static void switch_journal_file(void)
 
 retry:
 	if (!uatomic_set_true(&jfile.in_commit)) {
-		sd_eprintf("journal file in committing, "
-			   "you might need enlarge jfile size");
+		sd_err("journal file in committing, "
+		       "you might need enlarge jfile size");
 		usleep(100000); /* Wait until committing is finished */
 		goto retry;
 	}
@@ -394,7 +393,7 @@ static int journal_file_write(struct journal_descriptor *jd, const char *buf)
 	 */
 	written = xpwrite(jfile.fd, wbuffer, wsize, woff);
 	if (written != wsize) {
-		sd_eprintf("failed, written %zd, len %zd", written, wsize);
+		sd_err("failed, written %zd, len %zd", written, wsize);
 		/* FIXME: teach journal file handle EIO gracefully */
 		ret = SD_RES_EIO;
 		goto out;
diff --git a/sheep/md.c b/sheep/md.c
index 181ecbd..038c180 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -126,20 +126,19 @@ static int path_to_disk_idx(char *path)
 bool md_add_disk(char *path)
 {
 	if (path_to_disk_idx(path) != -1) {
-		sd_eprintf("duplicate path %s", path);
+		sd_err("duplicate path %s", path);
 		return false;
 	}
 
 	if (xmkdir(path, sd_def_dmode) < 0) {
-		sd_eprintf("can't mkdir for %s, %m", path);
+		sd_err("can't mkdir for %s, %m", path);
 		return false;
 	}
 
 	md_nr_disks++;
 
 	pstrcpy(md_disks[md_nr_disks - 1].path, PATH_MAX, path);
-	sd_iprintf("%s, nr %d", md_disks[md_nr_disks - 1].path,
-		   md_nr_disks);
+	sd_info("%s, nr %d", md_disks[md_nr_disks - 1].path, md_nr_disks);
 	return true;
 }
 
@@ -153,9 +152,9 @@ static inline void calculate_vdisks(struct disk *disks, int nr_disks,
 	for (i = 0; i < nr_disks; i++) {
 		factor = (float)disks[i].space / (float)avg_size;
 		md_disks[i].nr_vdisks = rintf(MD_DEFAULT_VDISKS * factor);
-		sd_dprintf("%s has %d vdisks, free space %" PRIu64,
-			   md_disks[i].path, md_disks[i].nr_vdisks,
-			   md_disks[i].space);
+		sd_debug("%s has %d vdisks, free space %" PRIu64,
+			 md_disks[i].path, md_disks[i].nr_vdisks,
+			 md_disks[i].space);
 	}
 }
 
@@ -192,7 +191,7 @@ static int for_each_object_in_path(char *path,
 
 	dir = opendir(path);
 	if (!dir) {
-		sd_eprintf("failed to open %s, %m", path);
+		sd_err("failed to open %s, %m", path);
 		return SD_RES_EIO;
 	}
 
@@ -212,7 +211,7 @@ static int for_each_object_in_path(char *path,
 			if (cleanup) {
 				snprintf(p, PATH_MAX, "%s/%016"PRIx64".tmp",
 					 path, oid);
-				sd_dprintf("remove tmp object %s", p);
+				sd_debug("remove tmp object %s", p);
 				unlink(p);
 			}
 			continue;
@@ -235,7 +234,7 @@ static uint64_t get_path_free_size(char *path, uint64_t *used)
 	uint64_t size;
 
 	if (statvfs(path, &fs) < 0) {
-		sd_eprintf("get disk %s space failed %m", path);
+		sd_err("get disk %s space failed %m", path);
 		return 0;
 	}
 	size = (int64_t)fs.f_frsize * fs.f_bavail;
@@ -260,13 +259,13 @@ static uint64_t init_path_space(char *path)
 	char stale[PATH_MAX];
 
 	if (!is_xattr_enabled(path)) {
-		sd_iprintf("multi-disk support need xattr feature");
+		sd_info("multi-disk support need xattr feature");
 		goto broken_path;
 	}
 
 	snprintf(stale, PATH_MAX, "%s/.stale", path);
 	if (xmkdir(stale, sd_def_dmode) < 0) {
-		sd_eprintf("can't mkdir for %s, %m", stale);
+		sd_err("can't mkdir for %s, %m", stale);
 		goto broken_path;
 	}
 
@@ -274,7 +273,7 @@ static uint64_t init_path_space(char *path)
 		if (errno == ENODATA) {
 			goto create;
 		} else {
-			sd_eprintf("%s, %m", path);
+			sd_err("%s, %m", path);
 			goto broken_path;
 		}
 	}
@@ -285,7 +284,7 @@ create:
 	if (!size)
 		goto broken_path;
 	if (setxattr(path, MDNAME, &size, MDSIZE, 0) < 0) {
-		sd_eprintf("%s, %m", path);
+		sd_err("%s, %m", path);
 		goto broken_path;
 	}
 	return size;
@@ -297,7 +296,7 @@ static inline void md_remove_disk(int idx)
 {
 	int i;
 
-	sd_iprintf("%s from multi-disk array", md_disks[idx].path);
+	sd_info("%s from multi-disk array", md_disks[idx].path);
 	/*
 	 * We need to keep last disk path to generate EIO when all disks are
 	 * broken
@@ -341,7 +340,7 @@ char *md_get_object_path(uint64_t oid)
 	vd = oid_to_vdisk(oid);
 	p = md_disks[vd->idx].path;
 	sd_unlock(&md_lock);
-	sd_dprintf("%d, %s", vd->idx, p);
+	sd_debug("%d, %s", vd->idx, p);
 
 	return p;
 }
@@ -381,7 +380,7 @@ int for_each_object_in_stale(int (*func)(uint64_t oid, char *path,
 	sd_read_lock(&md_lock);
 	for (i = 0; i < md_nr_disks; i++) {
 		snprintf(path, sizeof(path), "%s/.stale", md_disks[i].path);
-		sd_eprintf("%s", path);
+		sd_err("%s", path);
 		ret = for_each_object_in_path(path, func, false, arg);
 		if (ret != SD_RES_SUCCESS)
 			break;
@@ -460,7 +459,7 @@ static inline bool md_access(char *path)
 {
 	if (access(path, R_OK | W_OK) < 0) {
 		if (errno != ENOENT)
-			sd_eprintf("failed to check %s, %m", path);
+			sd_err("failed to check %s, %m", path);
 		return false;
 	}
 
@@ -495,19 +494,19 @@ static int md_move_object(uint64_t oid, char *old, char *new)
 
 	fd = open(old, O_RDONLY);
 	if (fd < 0) {
-		sd_eprintf("failed to open %s", old);
+		sd_err("failed to open %s", old);
 		goto out;
 	}
 
 	ret = strbuf_read(&buf, fd, sz);
 	if (ret != sz) {
-		sd_eprintf("failed to read %s, %d", old, ret);
+		sd_err("failed to read %s, %d", old, ret);
 		ret = -1;
 		goto out_close;
 	}
 
 	if (atomic_create_and_write(new, buf.buf, buf.len, false) < 0) {
-		sd_eprintf("failed to create %s", new);
+		sd_err("failed to create %s", new);
 		ret = -1;
 		goto out_close;
 	}
@@ -537,11 +536,11 @@ static int md_check_and_move(uint64_t oid, uint32_t epoch, char *path)
 
 	/* We can't use rename(2) accross device */
 	if (md_move_object(oid, old, new) < 0) {
-		sd_eprintf("move old %s to new %s failed", old, new);
+		sd_err("move old %s to new %s failed", old, new);
 		return SD_RES_EIO;
 	}
 
-	sd_dprintf("from %s to %s", old, new);
+	sd_debug("from %s to %s", old, new);
 	return SD_RES_SUCCESS;
 }
 
@@ -616,7 +615,7 @@ static inline void md_del_disk(char *path)
 	int idx = path_to_disk_idx(path);
 
 	if (idx < 0) {
-		sd_eprintf("invalid path %s", path);
+		sd_err("invalid path %s", path);
 		return;
 	}
 	md_remove_disk(idx);
diff --git a/sheep/migrate.c b/sheep/migrate.c
index b35548c..77fc6b9 100644
--- a/sheep/migrate.c
+++ b/sheep/migrate.c
@@ -79,7 +79,7 @@ static size_t get_file_size(const char *path)
 
 	ret = stat(path, &stbuf);
 	if (ret < 0) {
-		sd_eprintf("failed to stat %s, %m", path);
+		sd_err("failed to stat %s, %m", path);
 		return -1;
 	}
 	return stbuf.st_size;
@@ -122,7 +122,7 @@ static int backup_file(char *fname, char *suffix)
 	fd = open(fname, O_RDONLY);
 	if (fd < 0) {
 		if (errno != ENOENT) {
-			sd_eprintf("failed to open %s, %m", fname);
+			sd_err("failed to open %s, %m", fname);
 			ret = -1;
 		} else
 			ret = 0;
@@ -136,7 +136,7 @@ static int backup_file(char *fname, char *suffix)
 	buf = xmalloc(len);
 	ret = xread(fd, buf, len);
 	if (ret != len) {
-		sd_eprintf("failed to read %s, %d %m", fname, ret);
+		sd_err("failed to read %s, %d %m", fname, ret);
 		ret = -1;
 		goto out;
 	}
@@ -145,14 +145,14 @@ static int backup_file(char *fname, char *suffix)
 
 	fd = open(dst_file, O_CREAT | O_WRONLY | O_DSYNC, 0644);
 	if (fd < 0) {
-		sd_eprintf("failed to create %s, %m", dst_file);
+		sd_err("failed to create %s, %m", dst_file);
 		ret = -1;
 		goto out;
 	}
 
 	ret = xwrite(fd, buf, len);
 	if (ret != len) {
-		sd_eprintf("failed to write to %s, %d %m", dst_file, ret);
+		sd_err("failed to write to %s, %d %m", dst_file, ret);
 		ret = -1;
 	}
 out:
@@ -215,13 +215,13 @@ static int update_epoch_from_v0_to_v1(uint32_t epoch)
 		if (errno == ENOENT)
 			return 0;
 
-		sd_eprintf("failed to open epoch %"PRIu32" log", epoch);
+		sd_err("failed to open epoch %"PRIu32" log", epoch);
 		return -1;
 	}
 
 	ret = xread(fd, nodes_v0, sizeof(nodes_v0));
 	if (ret < 0) {
-		sd_eprintf("failed to read epoch %"PRIu32" log", epoch);
+		sd_err("failed to read epoch %"PRIu32" log", epoch);
 		close(fd);
 		return ret;
 	}
@@ -238,8 +238,7 @@ static int update_epoch_from_v0_to_v1(uint32_t epoch)
 	len = sizeof(nodes_v1[0]) * nr_nodes;
 	ret = xpwrite(fd, nodes_v1, len, 0);
 	if (ret != len) {
-		sd_eprintf("failed to write epoch %"PRIu32" log",
-			   epoch);
+		sd_err("failed to write epoch %"PRIu32" log", epoch);
 		close(fd);
 		return -1;
 	}
@@ -248,8 +247,7 @@ static int update_epoch_from_v0_to_v1(uint32_t epoch)
 
 	ret = xpwrite(fd, t, sizeof(*t), len);
 	if (ret != sizeof(*t)) {
-		sd_eprintf("failed to write time to epoch %"
-			   PRIu32" log", epoch);
+		sd_err("failed to write time to epoch %" PRIu32 " log", epoch);
 		close(fd);
 		return -1;
 	}
@@ -266,14 +264,14 @@ static int migrate_from_v0_to_v1(void)
 
 	fd = open(config_path, O_RDWR);
 	if (fd < 0) {
-		sd_eprintf("failed to open config file, %m");
+		sd_err("failed to open config file, %m");
 		return -1;
 	}
 
 	memset(&config, 0, sizeof(config));
 	ret = xread(fd, &config, sizeof(config));
 	if (ret < 0) {
-		sd_eprintf("failed to read config file, %m");
+		sd_err("failed to read config file, %m");
 		close(fd);
 		return ret;
 	}
@@ -281,7 +279,7 @@ static int migrate_from_v0_to_v1(void)
 	config.version = 1;
 	ret = xpwrite(fd, &config, sizeof(config), 0);
 	if (ret != sizeof(config)) {
-		sd_eprintf("failed to write config data, %m");
+		sd_err("failed to write config data, %m");
 		close(fd);
 		return -1;
 	}
@@ -289,7 +287,7 @@ static int migrate_from_v0_to_v1(void)
 	/* 0.5.1 could wrongly extend the config file, so truncate it here */
 	ret = xftruncate(fd, sizeof(config));
 	if (ret != 0) {
-		sd_eprintf("failed to truncate config data, %m");
+		sd_err("failed to truncate config data, %m");
 		close(fd);
 		return -1;
 	}
@@ -325,7 +323,7 @@ static int update_epoch_from_v1_to_v2(uint32_t epoch)
 		if (errno == ENOENT)
 			return 0;
 
-		sd_eprintf("failed to open epoch %"PRIu32" log", epoch);
+		sd_err("failed to open epoch %"PRIu32" log", epoch);
 		return -1;
 	}
 
@@ -335,14 +333,14 @@ static int update_epoch_from_v1_to_v2(uint32_t epoch)
 	 * the value of sd_node.nid.port
 	 */
 	if ((get_file_size(path) - sizeof(time_t)) % sizeof(nodes_v1[0]) != 0) {
-		sd_dprintf("%s is not a v1 format", path);
+		sd_debug("%s is not a v1 format", path);
 		close(fd);
 		return 0;
 	}
 
 	ret = xread(fd, nodes_v1, sizeof(nodes_v1));
 	if (ret < 0) {
-		sd_eprintf("failed to read epoch %"PRIu32" log", epoch);
+		sd_err("failed to read epoch %"PRIu32" log", epoch);
 		close(fd);
 		return ret;
 	}
@@ -350,7 +348,7 @@ static int update_epoch_from_v1_to_v2(uint32_t epoch)
 	nr_nodes = ret / sizeof(nodes_v1[0]);
 	for (int i = 0; i < nr_nodes; i++) {
 		if (nodes_v1[i].nid.port == 0) {
-			sd_dprintf("%s is not a v1 format", path);
+			sd_debug("%s is not a v1 format", path);
 			return 0;
 		}
 		memset(&nodes_v2[i].nid, 0, sizeof(nodes_v2[i].nid));
@@ -365,8 +363,7 @@ static int update_epoch_from_v1_to_v2(uint32_t epoch)
 	len = sizeof(nodes_v2[0]) * nr_nodes;
 	ret = xpwrite(fd, nodes_v2, len, 0);
 	if (ret != len) {
-		sd_eprintf("failed to write epoch %"PRIu32" log",
-			   epoch);
+		sd_err("failed to write epoch %"PRIu32" log", epoch);
 		close(fd);
 		return -1;
 	}
@@ -375,8 +372,7 @@ static int update_epoch_from_v1_to_v2(uint32_t epoch)
 
 	ret = xpwrite(fd, t, sizeof(*t), len);
 	if (ret != sizeof(*t)) {
-		sd_eprintf("failed to write time to epoch %"
-			   PRIu32" log", epoch);
+		sd_err("failed to write time to epoch %" PRIu32 " log", epoch);
 		close(fd);
 		return -1;
 	}
@@ -394,14 +390,14 @@ static int migrate_from_v1_to_v2(void)
 
 	fd = open(config_path, O_WRONLY | O_DSYNC);
 	if (fd < 0) {
-		sd_eprintf("failed to open config file, %m");
+		sd_err("failed to open config file, %m");
 		return -1;
 	}
 
 	ret = xpwrite(fd, &version, sizeof(version),
 		      offsetof(struct sheepdog_config_v2, version));
 	if (ret != sizeof(version)) {
-		sd_eprintf("failed to write config data, %m");
+		sd_err("failed to write config data, %m");
 		close(fd);
 		return -1;
 	}
@@ -409,7 +405,7 @@ static int migrate_from_v1_to_v2(void)
 	ret = xpwrite(fd, store, sizeof(store),
 		      offsetof(struct sheepdog_config_v2, store));
 	if (ret != sizeof(store)) {
-		sd_eprintf("failed to write config data, %m");
+		sd_err("failed to write config data, %m");
 		close(fd);
 		return -1;
 	}
@@ -435,7 +431,7 @@ int sd_migrate_store(int from, int to)
 
 	ret = backup_store();
 	if (ret != 0) {
-		sd_eprintf("failed to backup the old store");
+		sd_err("failed to backup the old store");
 		return ret;
 	}
 
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index c238725..7431cfa 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -321,9 +321,9 @@ static int remove_cache_object(struct object_cache *oc, uint32_t idx)
 
 	snprintf(path, sizeof(path), "%s/%06"PRIx32"/%08"PRIx32,
 		 object_cache_dir, oc->vid, idx);
-	sd_dprintf("%"PRIx64, idx_to_oid(oc->vid, idx));
+	sd_debug("%"PRIx64, idx_to_oid(oc->vid, idx));
 	if (unlink(path) < 0) {
-		sd_eprintf("failed to remove cached object %m");
+		sd_err("failed to remove cached object %m");
 		if (errno == ENOENT)
 			return SD_RES_SUCCESS;
 		ret = SD_RES_EIO;
@@ -350,7 +350,7 @@ static int read_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 
 	fd = open(p, flags, sd_def_fmode);
 	if (fd < 0) {
-		sd_eprintf("%m");
+		sd_err("%m");
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -358,8 +358,8 @@ static int read_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 	size = xpread(fd, buf, count, offset);
 
 	if (size != count) {
-		sd_eprintf("size %zu, count:%zu, offset %jd %m", size, count,
-			   (intmax_t)offset);
+		sd_err("size %zu, count:%zu, offset %jd %m", size, count,
+		       (intmax_t)offset);
 		ret = SD_RES_EIO;
 		goto out_close;
 	}
@@ -386,7 +386,7 @@ static int write_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 
 	fd = open(p, flags, sd_def_fmode);
 	if (fd < 0) {
-		sd_eprintf("%m");
+		sd_err("%m");
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -394,8 +394,8 @@ static int write_cache_object_noupdate(uint32_t vid, uint32_t idx, void *buf,
 	size = xpwrite(fd, buf, count, offset);
 
 	if (size != count) {
-		sd_eprintf("size %zu, count:%zu, offset %jd %m", size, count,
-			   (intmax_t)offset);
+		sd_err("size %zu, count:%zu, offset %jd %m", size, count,
+		       (intmax_t)offset);
 		ret = SD_RES_EIO;
 		goto out_close;
 	}
@@ -466,8 +466,8 @@ static int write_cache_object(struct object_cache_entry *entry, void *buf,
 
 	ret = exec_local_req(&hdr, buf);
 	if (ret != SD_RES_SUCCESS) {
-		sd_eprintf("failed to write object %" PRIx64 ", %s", oid,
-			   sd_strerror(ret));
+		sd_err("failed to write object %" PRIx64 ", %s", oid,
+		       sd_strerror(ret));
 		return ret;
 	}
 out:
@@ -486,15 +486,15 @@ static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
 	int first_bit, last_bit;
 
 	if (!bmap) {
-		sd_dprintf("WARN: nothing to flush %"PRIx64, oid);
+		sd_debug("WARN: nothing to flush %"PRIx64, oid);
 		return SD_RES_SUCCESS;
 	}
 
 	first_bit = ffsll(bmap) - 1;
 	last_bit = fls64(bmap) - 1;
 
-	sd_dprintf("%"PRIx64" bmap(%zd):0x%"PRIx64", first_bit:%d, last_bit:%d",
-		   oid, bsize, bmap, first_bit, last_bit);
+	sd_debug("%"PRIx64" bmap(%zd):0x%"PRIx64", first_bit:%d, last_bit:%d",
+		 oid, bsize, bmap, first_bit, last_bit);
 	offset = first_bit * bsize;
 	data_length = min((last_bit - first_bit + 1) * bsize,
 			  get_objsize(oid) - offset);
@@ -515,8 +515,8 @@ static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
 
 	ret = exec_local_req(&hdr, buf);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("failed to push object %"PRIx64", %s",
-			   oid, sd_strerror(ret));
+		sd_err("failed to push object %" PRIx64 ", %s", oid,
+		       sd_strerror(ret));
 out:
 	free(buf);
 	return ret;
@@ -546,7 +546,7 @@ static void do_reclaim_object(struct object_cache *oc)
 	list_for_each_entry_safe(entry, t, &oc->lru_head, lru_list) {
 		oid = idx_to_oid(oc->vid, entry_idx(entry));
 		if (entry_in_use(entry)) {
-			sd_dprintf("%"PRIx64" is in use, skip...", oid);
+			sd_debug("%"PRIx64" is in use, skip...", oid);
 			continue;
 		}
 
@@ -557,14 +557,14 @@ static void do_reclaim_object(struct object_cache *oc)
 		 * can reclaim them safely.
 		 */
 		if (entry_is_dirty(entry) && !oid_is_readonly(oid)) {
-			sd_dprintf("%"PRIx64" is dirty, skip...", oid);
+			sd_debug("%"PRIx64" is dirty, skip...", oid);
 			continue;
 		}
 		if (remove_cache_object(oc, entry_idx(entry)) != SD_RES_SUCCESS)
 			continue;
 		free_cache_entry(entry);
 		cap = uatomic_sub_return(&gcache.capacity, CACHE_OBJECT_SIZE);
-		sd_dprintf("%"PRIx64" reclaimed. capacity:%"PRId32, oid, cap);
+		sd_debug("%"PRIx64" reclaimed. capacity:%"PRId32, oid, cap);
 		if (cap <= HIGH_WATERMARK)
 			break;
 	}
@@ -599,13 +599,13 @@ static void do_reclaim(struct work *work)
 			cap = uatomic_read(&gcache.capacity);
 			if (cap <= HIGH_WATERMARK) {
 				sd_unlock(&hashtable_lock[idx]);
-				sd_dprintf("complete, capacity %"PRIu32, cap);
+				sd_debug("complete, capacity %"PRIu32, cap);
 				return;
 			}
 		}
 		sd_unlock(&hashtable_lock[idx]);
 	}
-	sd_dprintf("finished");
+	sd_debug("finished");
 }
 
 static void reclaim_done(struct work *work)
@@ -622,7 +622,7 @@ static int create_dir_for(uint32_t vid)
 
 	snprintf(p, sizeof(p), "%s/%06"PRIx32, object_cache_dir, vid);
 	if (xmkdir(p, sd_def_dmode) < 0) {
-		sd_eprintf("%s, %m", p);
+		sd_err("%s, %m", p);
 		ret = -1;
 	}
 	return ret;
@@ -708,7 +708,7 @@ static void add_to_lru_cache(struct object_cache *oc, uint32_t idx, bool create)
 {
 	struct object_cache_entry *entry = alloc_cache_entry(oc, idx);
 
-	sd_dprintf("oid %"PRIx64" added", idx_to_oid(oc->vid, idx));
+	sd_debug("oid %"PRIx64" added", idx_to_oid(oc->vid, idx));
 
 	write_lock_cache(oc);
 	if (lru_tree_insert(&oc->lru_tree, entry))
@@ -731,7 +731,7 @@ static inline int lookup_path(char *path)
 
 	if (access(path, R_OK | W_OK) < 0) {
 		if (errno != ENOENT) {
-			sd_dprintf("%m");
+			sd_debug("%m");
 			ret = SD_RES_EIO;
 		} else {
 			ret = SD_RES_NO_CACHE;
@@ -754,7 +754,7 @@ static int object_cache_lookup(struct object_cache *oc, uint32_t idx,
 	flags |= O_CREAT | O_TRUNC;
 	fd = open(path, flags, sd_def_fmode);
 	if (fd < 0) {
-		sd_dprintf("%s, %m", path);
+		sd_debug("%s, %m", path);
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -784,10 +784,10 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 	fd = open(tmp_path, flags, sd_def_fmode);
 	if (fd < 0) {
 		if (errno == EEXIST) {
-			sd_dprintf("%08"PRIx32" already created", idx);
+			sd_debug("%08"PRIx32" already created", idx);
 			goto out;
 		}
-		sd_dprintf("%m");
+		sd_debug("%m");
 		ret = SD_RES_EIO;
 		goto out;
 	}
@@ -797,7 +797,7 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 		ret = prealloc(fd, obj_size);
 		if (ret < 0) {
 			ret = SD_RES_EIO;
-			sd_eprintf("%m");
+			sd_err("%m");
 			goto out_close;
 		}
 	}
@@ -805,7 +805,7 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 	ret = xpwrite(fd, buffer, buf_size, offset);
 	if (ret != buf_size) {
 		ret = SD_RES_EIO;
-		sd_eprintf("failed, vid %"PRIx32", idx %"PRIx32, oc->vid, idx);
+		sd_err("failed, vid %"PRIx32", idx %"PRIx32, oc->vid, idx);
 		goto out_close;
 	}
 	/* This is intended to take care of partial write due to crash */
@@ -817,13 +817,13 @@ static int create_cache_object(struct object_cache *oc, uint32_t idx,
 			ret = SD_RES_OID_EXIST;
 			goto out_close;
 		}
-		sd_dprintf("failed to link %s to %s: %m", tmp_path, path);
+		sd_debug("failed to link %s to %s: %m", tmp_path, path);
 		/* FIXME: teach object cache handle EIO gracefully */
 		ret = SD_RES_EIO;
 		goto out_close;
 	}
 	ret = SD_RES_SUCCESS;
-	sd_dprintf("%08"PRIx32" size %zu", idx, obj_size);
+	sd_debug("%08"PRIx32" size %zu", idx, obj_size);
 out_close:
 	close(fd);
 	unlink(tmp_path);
@@ -850,7 +850,7 @@ static int object_cache_pull(struct object_cache *oc, uint32_t idx)
 	if (ret != SD_RES_SUCCESS)
 		goto err;
 
-	sd_dprintf("oid %"PRIx64" pulled successfully", oid);
+	sd_debug("oid %"PRIx64" pulled successfully", oid);
 	ret = create_cache_object(oc, idx, buf, rsp->data_length,
 				  rsp->obj.offset, data_length);
 	/*
@@ -883,7 +883,7 @@ static void do_push_object(struct work *work)
 	struct object_cache *oc = entry->oc;
 	uint64_t oid = idx_to_oid(oc->vid, entry_idx(entry));
 
-	sd_dprintf("%"PRIx64, oid);
+	sd_debug("%"PRIx64, oid);
 
 	read_lock_entry(entry);
 	/*
@@ -906,7 +906,7 @@ clean:
 	entry->bmap = 0;
 	unlock_entry(entry);
 
-	sd_dprintf("%"PRIx64" done", oid);
+	sd_debug("%"PRIx64" done", oid);
 	put_cache_entry(entry);
 }
 
@@ -951,7 +951,7 @@ static int object_cache_push(struct object_cache *oc)
 
 	eventfd_xread(oc->push_efd);
 
-	sd_dprintf("%"PRIx32" completed", oc->vid);
+	sd_debug("%"PRIx32" completed", oc->vid);
 	return SD_RES_SUCCESS;
 }
 
@@ -1027,7 +1027,7 @@ static struct object_cache_entry *oid_to_entry(uint64_t oid)
 	cache = find_object_cache(vid, false);
 	entry = get_cache_entry_from(cache, idx);
 	if (!entry) {
-		sd_dprintf("%" PRIx64 " doesn't exist", oid);
+		sd_debug("%" PRIx64 " doesn't exist", oid);
 		return NULL;
 	}
 	return entry;
@@ -1043,11 +1043,11 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 	int ret = 0;
 	char p[PATH_MAX];
 
-	sd_dprintf("%"PRIx32, vid);
+	sd_debug("%"PRIx32, vid);
 	snprintf(p, sizeof(p), "%s/%06"PRIx32, object_cache_dir, vid);
 	dir = opendir(p);
 	if (!dir) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		ret = -1;
 		goto out;
 	}
@@ -1056,9 +1056,9 @@ static int object_cache_flush_and_delete(struct object_cache *oc)
 		if (!strncmp(d->d_name, ".", 1))
 			continue;
 		if (strcmp(d->d_name + 8, ".tmp") == 0) {
-			sd_dprintf("try to del %s", d->d_name);
+			sd_debug("try to del %s", d->d_name);
 			if (unlinkat(dirfd(dir), d->d_name, 0) < 0)
-				sd_eprintf("%m");
+				sd_err("%m");
 			continue;
 		}
 
@@ -1126,8 +1126,8 @@ int object_cache_handle_request(struct request *req)
 	int ret;
 	bool create = false;
 
-	sd_dprintf("%08"PRIx32", len %"PRIu32", off %"PRIu64, idx,
-		   hdr->data_length, hdr->obj.offset);
+	sd_debug("%08" PRIx32 ", len %" PRIu32 ", off %" PRIu64, idx,
+		 hdr->data_length, hdr->obj.offset);
 
 	cache = find_object_cache(vid, true);
 
@@ -1148,7 +1148,7 @@ retry:
 
 	entry = get_cache_entry_from(cache, idx);
 	if (!entry) {
-		sd_dprintf("retry oid %"PRIx64, oid);
+		sd_debug("retry oid %"PRIx64, oid);
 		/*
 		 * For the case that object exists but isn't added to object
 		 * list yet, we call pthread_yield() to expect other thread can
@@ -1182,9 +1182,9 @@ int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
 	struct object_cache_entry *entry = oid_to_entry(oid);
 	int ret;
 
-	sd_dprintf("%" PRIx64, oid);
+	sd_debug("%" PRIx64, oid);
 	if (!entry) {
-		sd_dprintf("%" PRIx64 " doesn't exist", oid);
+		sd_debug("%" PRIx64 " doesn't exist", oid);
 		return SD_RES_NO_CACHE;
 	}
 
@@ -1199,9 +1199,9 @@ int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 	struct object_cache_entry *entry = oid_to_entry(oid);
 	int ret;
 
-	sd_dprintf("%" PRIx64, oid);
+	sd_debug("%" PRIx64, oid);
 	if (!entry) {
-		sd_dprintf("%" PRIx64 " doesn't exist", oid);
+		sd_debug("%" PRIx64 " doesn't exist", oid);
 		return SD_RES_NO_CACHE;
 	}
 
@@ -1217,7 +1217,7 @@ int object_cache_flush_vdi(uint32_t vid)
 
 	cache = find_object_cache(vid, false);
 	if (!cache) {
-		sd_dprintf("%"PRIx32" not found", vid);
+		sd_debug("%"PRIx32" not found", vid);
 		return SD_RES_SUCCESS;
 	}
 
@@ -1259,7 +1259,7 @@ static int load_cache_object(struct object_cache *cache)
 		 cache->vid);
 	dir = opendir(path);
 	if (!dir) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		ret = -1;
 		goto out;
 	}
@@ -1269,9 +1269,9 @@ static int load_cache_object(struct object_cache *cache)
 			continue;
 
 		if (strcmp(d->d_name + 8, ".tmp") == 0) {
-			sd_dprintf("try to del %s", d->d_name);
+			sd_debug("try to del %s", d->d_name);
 			if (unlinkat(dirfd(dir), d->d_name, 0) < 0)
-				sd_eprintf("%m");
+				sd_err("%m");
 			continue;
 		}
 
@@ -1286,7 +1286,7 @@ static int load_cache_object(struct object_cache *cache)
 		 * cluster isn't fully working.
 		 */
 		add_to_lru_cache(cache, idx, true);
-		sd_dprintf("%"PRIx64, idx_to_oid(cache->vid, idx));
+		sd_debug("%"PRIx64, idx_to_oid(cache->vid, idx));
 	}
 
 	closedir(dir);
@@ -1305,7 +1305,7 @@ static int load_cache(void)
 	snprintf(path, sizeof(path), "%s", object_cache_dir);
 	dir = opendir(path);
 	if (!dir) {
-		sd_dprintf("%m");
+		sd_debug("%m");
 		ret = -1;
 		goto out;
 	}
@@ -1335,7 +1335,7 @@ int object_cache_remove(uint64_t oid)
 	if (!entry)
 		return SD_RES_NO_OBJ;
 
-	sd_dprintf("%" PRIx64, oid);
+	sd_debug("%" PRIx64, oid);
 	while (refcount_read(&entry->refcnt) > 1)
 		usleep(100000); /* Object might be in push */
 
@@ -1367,13 +1367,13 @@ int object_cache_init(const char *p)
 
 	strbuf_addstr(&buf, p);
 	if (xmkdir(buf.buf, sd_def_dmode) < 0) {
-		sd_eprintf("%s %m", buf.buf);
+		sd_err("%s %m", buf.buf);
 		ret = -1;
 		goto err;
 	}
 	strbuf_addstr(&buf, "/cache");
 	if (xmkdir(buf.buf, sd_def_dmode) < 0) {
-		sd_eprintf("%s %m", buf.buf);
+		sd_err("%s %m", buf.buf);
 		ret = -1;
 		goto err;
 	}
diff --git a/sheep/object_list_cache.c b/sheep/object_list_cache.c
index fc912ca..1710522 100644
--- a/sheep/object_list_cache.c
+++ b/sheep/object_list_cache.c
@@ -149,7 +149,7 @@ int get_obj_list(const struct sd_req *hdr, struct sd_rsp *rsp, void *data)
 out:
 	if (hdr->data_length < obj_list_cache.cache_size * sizeof(uint64_t)) {
 		sd_unlock(&obj_list_cache.lock);
-		sd_eprintf("GET_OBJ_LIST buffer too small");
+		sd_err("GET_OBJ_LIST buffer too small");
 		return SD_RES_BUFFER_SMALL;
 	}
 
@@ -174,8 +174,8 @@ static void objlist_deletion_work(struct work *work)
 	 * again, in which case we should not reclaim the cached entry.
 	 */
 	if (vdi_exist(vid)) {
-		sd_dprintf("VDI (%" PRIx32 ") is still in use, can not be"
-			" deleted", vid);
+		sd_debug("VDI (%" PRIx32 ") is still in use, can not be"
+			 " deleted", vid);
 		return;
 	}
 
@@ -184,7 +184,7 @@ static void objlist_deletion_work(struct work *work)
 		entry_vid = oid_to_vid(entry->oid);
 		if (entry_vid != vid)
 			continue;
-		sd_dprintf("delete object entry %" PRIx64, entry->oid);
+		sd_debug("delete object entry %" PRIx64, entry->oid);
 		list_del(&entry->list);
 		rb_erase(&entry->node, &obj_list_cache.root);
 		free(entry);
diff --git a/sheep/ops.c b/sheep/ops.c
index 65c068a..d0937f8 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -94,7 +94,7 @@ static int post_cluster_new_vdi(const struct sd_req *req, struct sd_rsp *rsp,
 	unsigned long nr = rsp->vdi.vdi_id;
 	int ret = rsp->result;
 
-	sd_dprintf("done %d %lx", ret, nr);
+	sd_debug("done %d %lx", ret, nr);
 	if (ret == SD_RES_SUCCESS)
 		set_bit(nr, sys->vdi_inuse);
 
@@ -209,11 +209,11 @@ static int remove_epoch(uint32_t epoch)
 	int ret;
 	char path[PATH_MAX];
 
-	sd_dprintf("remove epoch %"PRIu32, epoch);
+	sd_debug("remove epoch %"PRIu32, epoch);
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
 	ret = unlink(path);
 	if (ret && ret != -ENOENT) {
-		sd_eprintf("failed to remove %s: %s", path, strerror(-ret));
+		sd_err("failed to remove %s: %s", path, strerror(-ret));
 		return SD_RES_EIO;
 	}
 
@@ -336,8 +336,8 @@ static int local_release_vdi(struct request *req)
 		return SD_RES_SUCCESS;
 
 	if (!vid) {
-		sd_iprintf("Some VDI failed to release the object cache. "
-			   "Probably you are running old QEMU.");
+		sd_info("Some VDI failed to release the object cache. "
+			"Probably you are running old QEMU.");
 		return SD_RES_SUCCESS;
 	}
 
@@ -401,7 +401,7 @@ static int local_stat_cluster(struct request *req)
 	uint32_t epoch;
 
 	if (req->vinfo == NULL) {
-		sd_dprintf("cluster is not started up");
+		sd_debug("cluster is not started up");
 		goto out;
 	}
 
@@ -461,7 +461,7 @@ static int local_get_epoch(struct request *req)
 	int nr_nodes, nodes_len;
 	time_t timestamp;
 
-	sd_dprintf("%d", epoch);
+	sd_debug("%d", epoch);
 
 	nr_nodes =
 		epoch_log_read_with_timestamp(epoch, req->data,
@@ -493,15 +493,14 @@ static int cluster_force_recover_work(struct request *req)
 
 	old_vnode_info = get_vnode_info_epoch(epoch, req->vinfo);
 	if (!old_vnode_info) {
-		sd_printf(SDOG_EMERG, "cannot get vnode info for epoch %d",
-			  epoch);
+		sd_emerg("cannot get vnode info for epoch %d", epoch);
 		put_vnode_info(old_vnode_info);
 		return SD_RES_FORCE_RECOVER;
 	}
 
 	if (req->rq.data_length <
 	    sizeof(*old_vnode_info->nodes) * old_vnode_info->nr_nodes) {
-		sd_eprintf("too small buffer size, %d", req->rq.data_length);
+		sd_err("too small buffer size, %d", req->rq.data_length);
 		return SD_RES_INVALID_PARMS;
 	}
 
@@ -525,13 +524,13 @@ static int cluster_force_recover_main(const struct sd_req *req,
 	size_t nr_nodes = rsp->data_length / sizeof(*nodes);
 
 	if (rsp->epoch != sys->cinfo.epoch) {
-		sd_eprintf("epoch was incremented while cluster_force_recover");
+		sd_err("epoch was incremented while cluster_force_recover");
 		return SD_RES_FORCE_RECOVER;
 	}
 
 	ret = inc_and_log_epoch();
 	if (ret) {
-		sd_printf(SDOG_EMERG, "cannot update epoch log");
+		sd_emerg("cannot update epoch log");
 		goto err;
 	}
 
@@ -623,7 +622,7 @@ static int cluster_recovery_completion(const struct sd_req *req,
 		return SD_RES_SUCCESS;
 
 	if (latest_epoch < epoch) {
-		sd_dprintf("new epoch %d", epoch);
+		sd_debug("new epoch %d", epoch);
 		latest_epoch = epoch;
 		nr_recovereds = 0;
 	}
@@ -631,9 +630,9 @@ static int cluster_recovery_completion(const struct sd_req *req,
 	recovereds[nr_recovereds++] = *node;
 	xqsort(recovereds, nr_recovereds, node_cmp);
 
-	sd_dprintf("%s is recovered at epoch %d", node_to_str(node), epoch);
+	sd_debug("%s is recovered at epoch %d", node_to_str(node), epoch);
 	for (i = 0; i < nr_recovereds; i++)
-		sd_dprintf("[%x] %s", i, node_to_str(recovereds + i));
+		sd_debug("[%x] %s", i, node_to_str(recovereds + i));
 
 	if (sys->cinfo.epoch != latest_epoch)
 		return SD_RES_SUCCESS;
@@ -646,7 +645,7 @@ static int cluster_recovery_completion(const struct sd_req *req,
 				break;
 		}
 		if (i == nr_recovereds) {
-			sd_dprintf("all nodes are recovered, epoch %d", epoch);
+			sd_debug("all nodes are recovered, epoch %d", epoch);
 			/* sd_store can be NULL if this node is a gateway */
 			if (sd_store && sd_store->cleanup)
 				sd_store->cleanup();
@@ -676,8 +675,8 @@ static bool node_size_varied(void)
 	}
 
 	diff = new > old ? (double)(new - old) : (double)(old - new);
-	sd_dprintf("new %"PRIu64 ", old %"PRIu64", ratio %f", new, old,
-		   diff / (double)old);
+	sd_debug("new %"PRIu64 ", old %"PRIu64", ratio %f", new, old,
+		 diff / (double)old);
 	if (diff / (double)old < 0.01)
 		return false;
 
@@ -764,13 +763,13 @@ static int local_discard_obj(struct request *req)
 	uint32_t vid = oid_to_vid(oid), zero = 0;
 	int ret, idx = data_oid_to_idx(oid);
 
-	sd_dprintf("%"PRIx64, oid);
+	sd_debug("%"PRIx64, oid);
 	ret = write_object(vid_to_vdi_oid(vid), (char *)&zero, sizeof(zero),
 			   SD_INODE_HEADER_SIZE + sizeof(vid) * idx, false);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
 	if (remove_object(oid) != SD_RES_SUCCESS)
-		sd_eprintf("failed to remove %"PRIx64, oid);
+		sd_err("failed to remove %"PRIx64, oid);
 	/*
 	 * Return success even if remove_object fails because we have updated
 	 * inode successfully.
@@ -816,7 +815,7 @@ static int local_trace_read_buf(struct request *request)
 		return SD_RES_AGAIN;
 
 	rsp->data_length = ret;
-	sd_dprintf("%u", rsp->data_length);
+	sd_debug("%u", rsp->data_length);
 	return SD_RES_SUCCESS;
 }
 
@@ -938,14 +937,14 @@ int peer_create_and_write_obj(struct request *req)
 	iocb.epoch = epoch;
 	iocb.length = get_objsize(oid);
 	if (hdr->flags & SD_FLAG_CMD_COW) {
-		sd_dprintf("%" PRIx64 ", %" PRIx64, oid, hdr->obj.cow_oid);
+		sd_debug("%" PRIx64 ", %" PRIx64, oid, hdr->obj.cow_oid);
 
 		buf = xvalloc(SD_DATA_OBJ_SIZE);
 		if (hdr->data_length != SD_DATA_OBJ_SIZE) {
 			ret = read_copy_from_replica(req, hdr->epoch,
 						     hdr->obj.cow_oid, buf);
 			if (ret != SD_RES_SUCCESS) {
-				sd_eprintf("failed to read cow object");
+				sd_err("failed to read cow object");
 				goto out;
 			}
 		}
@@ -1331,16 +1330,15 @@ void do_process_work(struct work *work)
 	struct request *req = container_of(work, struct request, work);
 	int ret = SD_RES_SUCCESS;
 
-	sd_dprintf("%x, %" PRIx64", %"PRIu32, req->rq.opcode, req->rq.obj.oid,
-		   req->rq.epoch);
+	sd_debug("%x, %" PRIx64", %"PRIu32, req->rq.opcode, req->rq.obj.oid,
+		 req->rq.epoch);
 
 	if (req->op->process_work)
 		ret = req->op->process_work(req);
 
 	if (ret != SD_RES_SUCCESS) {
-		sd_dprintf("failed: %x, %" PRIx64" , %u, %s",
-			   req->rq.opcode, req->rq.obj.oid, req->rq.epoch,
-			   sd_strerror(ret));
+		sd_debug("failed: %x, %" PRIx64" , %u, %s", req->rq.opcode,
+			 req->rq.obj.oid, req->rq.epoch, sd_strerror(ret));
 	}
 
 	req->rp.result = ret;
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index bebe2f3..d3c57e6 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -65,29 +65,29 @@ static int err_to_sderr(char *path, uint64_t oid, int err)
 	struct stat s;
 	char *dir = dirname(path);
 
-	sd_dprintf("%s", dir);
+	sd_debug("%s", dir);
 	switch (err) {
 	case ENOENT:
 		if (stat(dir, &s) < 0) {
-			sd_eprintf("%s corrupted", dir);
+			sd_err("%s corrupted", dir);
 			return md_handle_eio(dir);
 		}
-		sd_dprintf("object %016" PRIx64 " not found locally", oid);
+		sd_debug("object %016" PRIx64 " not found locally", oid);
 		return SD_RES_NO_OBJ;
 	case ENOSPC:
 		/* TODO: stop automatic recovery */
-		sd_eprintf("diskfull, oid=%"PRIx64, oid);
+		sd_err("diskfull, oid=%"PRIx64, oid);
 		return SD_RES_NO_SPACE;
 	case EMFILE:
 	case ENFILE:
 	case EINTR:
 	case EAGAIN:
 	case EEXIST:
-		sd_eprintf("%m, oid=%"PRIx64, oid);
+		sd_err("%m, oid=%"PRIx64, oid);
 		/* make gateway try again */
 		return SD_RES_NETWORK_ERROR;
 	default:
-		sd_eprintf("oid=%"PRIx64", %m", oid);
+		sd_err("oid=%"PRIx64", %m", oid);
 		return md_handle_eio(dir);
 	}
 }
@@ -100,7 +100,7 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 	ssize_t size;
 
 	if (iocb->epoch < sys_epoch()) {
-		sd_dprintf("%"PRIu32" sys %"PRIu32, iocb->epoch, sys_epoch());
+		sd_debug("%"PRIu32" sys %"PRIu32, iocb->epoch, sys_epoch());
 		return SD_RES_OLD_NODE_VER;
 	}
 
@@ -108,7 +108,7 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 	    journal_write_store(oid, iocb->buf, iocb->length, iocb->offset,
 				false)
 	    != SD_RES_SUCCESS) {
-		sd_eprintf("turn off journaling");
+		sd_err("turn off journaling");
 		uatomic_set_false(&sys->use_journal);
 		flags |= O_DSYNC;
 		sync();
@@ -122,9 +122,9 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 
 	size = xpwrite(fd, iocb->buf, iocb->length, iocb->offset);
 	if (size != iocb->length) {
-		sd_eprintf("failed to write object %"PRIx64", path=%s, offset=%"
-			   PRId64", size=%"PRId32", result=%zd, %m", oid, path,
-			   iocb->offset, iocb->length, size);
+		sd_err("failed to write object %"PRIx64", path=%s, offset=%"
+		       PRId64", size=%"PRId32", result=%zd, %m", oid, path,
+		       iocb->offset, iocb->length, size);
 		ret = err_to_sderr(path, oid, errno);
 		goto out;
 	}
@@ -139,7 +139,7 @@ static int make_stale_dir(char *path)
 
 	snprintf(p, PATH_MAX, "%s/.stale", path);
 	if (xmkdir(p, sd_def_dmode) < 0) {
-		sd_eprintf("%s failed, %m", p);
+		sd_err("%s failed, %m", p);
 		return SD_RES_EIO;
 	}
 	return SD_RES_SUCCESS;
@@ -184,8 +184,8 @@ static int init_vdi_state(uint64_t oid, char *wd, uint32_t epoch)
 
 	ret = default_read(oid, &iocb);
 	if (ret != SD_RES_SUCCESS) {
-		sd_eprintf("failed to read inode header %" PRIx64 " %" PRId32,
-			   oid, epoch);
+		sd_err("failed to read inode header %" PRIx64 " %" PRId32, oid,
+		       epoch);
 		goto out;
 	}
 
@@ -205,7 +205,7 @@ static int init_objlist_and_vdi_bitmap(uint64_t oid, char *wd, uint32_t epoch,
 	objlist_cache_insert(oid);
 
 	if (is_vdi_obj(oid)) {
-		sd_dprintf("found the VDI object %" PRIx64, oid);
+		sd_debug("found the VDI object %" PRIx64, oid);
 		set_bit(oid_to_vid(oid), sys->vdi_inuse);
 		ret = init_vdi_state(oid, wd, epoch);
 		if (ret != SD_RES_SUCCESS)
@@ -218,7 +218,7 @@ int default_init(void)
 {
 	int ret;
 
-	sd_dprintf("use plain store driver");
+	sd_debug("use plain store driver");
 	ret = for_each_obj_path(make_stale_dir);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
@@ -242,9 +242,9 @@ static int default_read_from_path(uint64_t oid, char *path,
 
 	size = xpread(fd, iocb->buf, iocb->length, iocb->offset);
 	if (size != iocb->length) {
-		sd_eprintf("failed to read object %"PRIx64", path=%s, offset=%"
-			   PRId64", size=%"PRId32", result=%zd, %m", oid, path,
-			   iocb->offset, iocb->length, size);
+		sd_err("failed to read object %"PRIx64", path=%s, offset=%"
+		       PRId64", size=%"PRId32", result=%zd, %m", oid, path,
+		       iocb->offset, iocb->length, size);
 		ret = err_to_sderr(path, oid, errno);
 	}
 	close(fd);
@@ -278,7 +278,7 @@ int prealloc(int fd, uint32_t size)
 	int ret = xfallocate(fd, 0, 0, size);
 	if (ret < 0) {
 		if (errno != ENOSYS && errno != EOPNOTSUPP) {
-			sd_eprintf("failed to preallocate space, %m");
+			sd_err("failed to preallocate space, %m");
 			return ret;
 		}
 
@@ -302,7 +302,7 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 	    journal_write_store(oid, iocb->buf, iocb->length,
 				iocb->offset, true)
 	    != SD_RES_SUCCESS) {
-		sd_eprintf("turn off journaling");
+		sd_err("turn off journaling");
 		uatomic_set_false(&sys->use_journal);
 		flags |= O_DSYNC;
 		sync();
@@ -318,11 +318,11 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 			 * same time.  They should try to write the same date,
 			 * so it is okay to simply return success here.
 			 */
-			sd_dprintf("%s exists", tmp_path);
+			sd_debug("%s exists", tmp_path);
 			return SD_RES_SUCCESS;
 		}
 
-		sd_eprintf("failed to open %s: %m", tmp_path);
+		sd_err("failed to open %s: %m", tmp_path);
 		return err_to_sderr(path, oid, errno);
 	}
 
@@ -336,18 +336,18 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 
 	ret = xpwrite(fd, iocb->buf, len, iocb->offset);
 	if (ret != len) {
-		sd_eprintf("failed to write object. %m");
+		sd_err("failed to write object. %m");
 		ret = err_to_sderr(path, oid, errno);
 		goto out;
 	}
 
 	ret = rename(tmp_path, path);
 	if (ret < 0) {
-		sd_eprintf("failed to rename %s to %s: %m", tmp_path, path);
+		sd_err("failed to rename %s to %s: %m", tmp_path, path);
 		ret = err_to_sderr(path, oid, errno);
 		goto out;
 	}
-	sd_dprintf("%"PRIx64, oid);
+	sd_debug("%"PRIx64, oid);
 	ret = SD_RES_SUCCESS;
 out:
 	if (ret != SD_RES_SUCCESS)
@@ -360,8 +360,8 @@ int default_link(uint64_t oid, uint32_t tgt_epoch)
 {
 	char path[PATH_MAX], stale_path[PATH_MAX];
 
-	sd_dprintf("try link %"PRIx64" from snapshot with epoch %d", oid,
-		   tgt_epoch);
+	sd_debug("try link %"PRIx64" from snapshot with epoch %d", oid,
+		 tgt_epoch);
 
 	get_obj_path(oid, path);
 	get_stale_obj_path(oid, tgt_epoch, stale_path);
@@ -374,8 +374,7 @@ int default_link(uint64_t oid, uint32_t tgt_epoch)
 		if (errno == EEXIST)
 			goto out;
 
-		sd_dprintf("failed to link from %s to %s, %m", stale_path,
-			   path);
+		sd_debug("failed to link from %s to %s, %m", stale_path, path);
 		return err_to_sderr(path, oid, errno);
 	}
 out:
@@ -422,12 +421,12 @@ static int move_object_to_stale_dir(uint64_t oid, char *wd, uint32_t epoch,
 		 oid, tgt_epoch);
 
 	if (rename(path, stale_path) < 0) {
-		sd_eprintf("failed to move stale object %"PRIX64" to %s, %m",
-			   oid, path);
+		sd_err("failed to move stale object %" PRIX64 " to %s, %m", oid,
+		       path);
 		return SD_RES_EIO;
 	}
 
-	sd_dprintf("moved object %"PRIx64, oid);
+	sd_debug("moved object %"PRIx64, oid);
 	return SD_RES_SUCCESS;
 }
 
@@ -450,7 +449,7 @@ int default_format(void)
 {
 	unsigned ret;
 
-	sd_dprintf("try get a clean store");
+	sd_debug("try get a clean store");
 	ret = for_each_obj_path(purge_dir);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
@@ -474,7 +473,7 @@ int default_remove_object(uint64_t oid)
 		if (errno == ENOENT)
 			return SD_RES_NO_OBJ;
 
-		sd_eprintf("failed to remove object %"PRIx64", %m", oid);
+		sd_err("failed to remove object %"PRIx64", %m", oid);
 		return SD_RES_EIO;
 	}
 
@@ -487,7 +486,7 @@ static int get_object_sha1(char *path, uint8_t *sha1)
 {
 	if (getxattr(path, SHA1NAME, sha1, SHA1_DIGEST_SIZE)
 	    != SHA1_DIGEST_SIZE) {
-		sd_eprintf("fail to get sha1, %s", path);
+		sd_err("fail to get sha1, %s", path);
 		return -1;
 	}
 
@@ -500,7 +499,7 @@ static int set_object_sha1(char *path, const uint8_t *sha1)
 
 	ret = setxattr(path, SHA1NAME, sha1, SHA1_DIGEST_SIZE, 0);
 	if (ret < 0)
-		sd_eprintf("fail to set sha1, %s", path);
+		sd_err("fail to set sha1, %s", path);
 
 	return ret;
 }
@@ -537,8 +536,8 @@ int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
 
 	if (is_readonly_obj) {
 		if (get_object_sha1(path, sha1) == 0) {
-			sd_dprintf("use cached sha1 digest %s",
-				   sha1_to_hex(sha1));
+			sd_debug("use cached sha1 digest %s",
+				 sha1_to_hex(sha1));
 			return SD_RES_SUCCESS;
 		}
 	}
@@ -561,8 +560,8 @@ int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
 	sha1_from_buffer(buf, length, sha1);
 	free(buf);
 
-	sd_dprintf("the message digest of %"PRIx64" at epoch %d is %s", oid,
-		   epoch, sha1_to_hex(sha1));
+	sd_debug("the message digest of %"PRIx64" at epoch %d is %s", oid,
+		 epoch, sha1_to_hex(sha1));
 
 	if (is_readonly_obj)
 		set_object_sha1(path, sha1);
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 7698235..5aabd30 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -126,8 +126,7 @@ static int recover_object_from(struct recovery_obj_work *row,
 
 		if (memcmp(rsp->hash.digest, sha1,
 			   sizeof(SHA1_DIGEST_SIZE)) == 0) {
-			sd_dprintf("use local replica at epoch %d",
-				   local_epoch);
+			sd_debug("use local replica at epoch %d", local_epoch);
 			ret = sd_store->link(oid, local_epoch);
 			if (ret == SD_RES_SUCCESS)
 				return ret;
@@ -207,8 +206,8 @@ static int recover_object_from_replica(struct recovery_obj_work *row,
 		ret = recover_object_from(row, node, tgt_epoch);
 		switch (ret) {
 		case SD_RES_SUCCESS:
-			sd_dprintf("recovered oid %"PRIx64" from %d "
-				   "to epoch %d", oid, tgt_epoch, epoch);
+			sd_debug("recovered oid %"PRIx64" from %d to epoch %d",
+				 oid, tgt_epoch, epoch);
 			objlist_cache_insert(oid);
 			return ret;
 		case SD_RES_OLD_NODE_VER:
@@ -250,8 +249,8 @@ static int do_recover_object(struct recovery_obj_work *row)
 
 	old = grab_vnode_info(rw->old_vinfo);
 again:
-	sd_dprintf("try recover object %"PRIx64" from epoch %"PRIu32, oid,
-		   tgt_epoch);
+	sd_debug("try recover object %"PRIx64" from epoch %"PRIu32, oid,
+		 tgt_epoch);
 
 	ret = recover_object_from_replica(row, old, tgt_epoch);
 
@@ -263,16 +262,16 @@ again:
 		row->stop = true;
 		break;
 	case SD_RES_STALE_OBJ:
-		sd_printf(SDOG_ALERT, "cannot access any replicas of "
-			  "%"PRIx64" at epoch %d", oid, tgt_epoch);
-		sd_printf(SDOG_ALERT, "clients may see old data");
+		sd_alert("cannot access any replicas of %"PRIx64" at epoch %d",
+			 oid, tgt_epoch);
+		sd_alert("clients may see old data");
 		/* fall through */
 	default:
 		/* No luck, roll back to an older configuration and try again */
 rollback:
 		tgt_epoch--;
 		if (tgt_epoch < 1) {
-			sd_eprintf("can not recover oid %"PRIx64, oid);
+			sd_err("can not recover oid %"PRIx64, oid);
 			ret = -1;
 			break;
 		}
@@ -280,8 +279,8 @@ rollback:
 		new_old = get_vnode_info_epoch(tgt_epoch, rw->cur_vinfo);
 		if (!new_old) {
 			/* We rollback in case we don't get a valid epoch */
-			sd_printf(SDOG_ALERT, "cannot get epoch %d", tgt_epoch);
-			sd_printf(SDOG_ALERT, "clients may see old data");
+			sd_alert("cannot get epoch %d", tgt_epoch);
+			sd_alert("clients may see old data");
 			goto rollback;
 		}
 
@@ -305,7 +304,7 @@ static void recover_object_work(struct work *work)
 	int ret, epoch;
 
 	if (sd_store->exist(oid)) {
-		sd_dprintf("the object is already recovered");
+		sd_debug("the object is already recovered");
 		return;
 	}
 
@@ -313,7 +312,7 @@ static void recover_object_work(struct work *work)
 	for (epoch = sys_epoch() - 1; epoch > 0; epoch--) {
 		ret = sd_store->get_hash(oid, epoch, row->local_sha1);
 		if (ret == SD_RES_SUCCESS) {
-			sd_dprintf("replica found in local at epoch %d", epoch);
+			sd_debug("replica found in local at epoch %d", epoch);
 			row->local_epoch = epoch;
 			break;
 		}
@@ -321,7 +320,7 @@ static void recover_object_work(struct work *work)
 
 	ret = do_recover_object(row);
 	if (ret < 0)
-		sd_eprintf("failed to recover object %"PRIx64, oid);
+		sd_err("failed to recover object %"PRIx64, oid);
 }
 
 bool node_in_recovery(void)
@@ -343,8 +342,8 @@ static inline void prepare_schedule_oid(uint64_t oid)
 	 */
 	for (i = 0; i < rinfo->done; i++)
 		if (rinfo->oids[i] == oid) {
-			sd_dprintf("%"PRIx64" not recovered, don't schedule it",
-				   oid);
+			sd_debug("%"PRIx64" not recovered, don't schedule it",
+				 oid);
 			return;
 		}
 	/* When recovery is not suspended, oid is currently being recovered */
@@ -355,7 +354,7 @@ static inline void prepare_schedule_oid(uint64_t oid)
 	rinfo->prio_oids = xrealloc(rinfo->prio_oids,
 				    rinfo->nr_prio_oids * sizeof(uint64_t));
 	rinfo->prio_oids[rinfo->nr_prio_oids - 1] = oid;
-	sd_dprintf("%"PRIx64" nr_prio_oids %"PRIu64, oid, rinfo->nr_prio_oids);
+	sd_debug("%"PRIx64" nr_prio_oids %"PRIu64, oid, rinfo->nr_prio_oids);
 
 	resume_suspended_recovery();
 }
@@ -369,7 +368,7 @@ bool oid_in_recovery(uint64_t oid)
 		return false;
 
 	if (sd_store->exist(oid)) {
-		sd_dprintf("the object %" PRIx64 " is already recoverd", oid);
+		sd_debug("the object %" PRIx64 " is already recoverd", oid);
 		return false;
 	}
 
@@ -394,7 +393,7 @@ bool oid_in_recovery(uint64_t oid)
 	 * in the list
 	 */
 	if (i == rinfo->count) {
-		sd_eprintf("%"PRIx64" is not in the recovery list", oid);
+		sd_err("%"PRIx64" is not in the recovery list", oid);
 		return false;
 	}
 
@@ -457,7 +456,7 @@ static inline bool run_next_rw(void)
 	main_thread_set(current_rinfo, nrinfo);
 	wakeup_all_requests();
 	queue_recovery_work(nrinfo);
-	sd_dprintf("recovery work is superseded");
+	sd_debug("recovery work is superseded");
 	return true;
 }
 
@@ -475,8 +474,7 @@ static void notify_recovery_completion_work(struct work *work)
 
 	ret = exec_local_req(&hdr, &sys->this_node);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("failed to notify recovery completion, %d",
-			   rw->epoch);
+		sd_err("failed to notify recovery completion, %d", rw->epoch);
 }
 
 static void notify_recovery_completion_main(struct work *work)
@@ -500,7 +498,7 @@ static inline void finish_recovery(struct recovery_info *rinfo)
 
 	free_recovery_info(rinfo);
 
-	sd_dprintf("recovery complete: new epoch %"PRIu32, recovered_epoch);
+	sd_debug("recovery complete: new epoch %"PRIu32, recovered_epoch);
 }
 
 static inline bool oid_in_prio_oids(struct recovery_info *rinfo, uint64_t oid)
@@ -540,10 +538,10 @@ static inline void finish_schedule_oids(struct recovery_info *rinfo)
 		new_oids[new_idx++] = rinfo->oids[i];
 	}
 	/* rw->count should eq new_idx, otherwise something is wrong */
-	sd_dprintf("%snr_recovered %"PRIu64", nr_prio_oids %"PRIu64", "
-		   "count %"PRIu64" = new %"PRIu64,
-		   rinfo->count == new_idx ? "" : "WARN: ", nr_recovered,
-		   rinfo->nr_prio_oids, rinfo->count, new_idx);
+	sd_debug("%snr_recovered %" PRIu64 ", nr_prio_oids %" PRIu64 ", count %"
+		 PRIu64 " = new %" PRIu64,
+		 rinfo->count == new_idx ? "" : "WARN: ", nr_recovered,
+		 rinfo->nr_prio_oids, rinfo->count, new_idx);
 
 	free(rinfo->oids);
 	rinfo->oids = new_oids;
@@ -575,7 +573,7 @@ static void recover_next_object(struct recovery_info *rinfo)
 		finish_schedule_oids(rinfo);
 
 	if (sys->cinfo.disable_recovery && !has_scheduled_objects(rinfo)) {
-		sd_dprintf("suspended");
+		sd_debug("suspended");
 		rinfo->suspended = true;
 		/* suspend until resume_suspended_recovery() is called */
 		return;
@@ -614,15 +612,15 @@ static void recover_object_main(struct work *work)
 		 * requests
 		 */
 		wakeup_all_requests();
-		sd_dprintf("recovery is stopped");
+		sd_debug("recovery is stopped");
 		goto out;
 	}
 
 	wakeup_requests_on_oid(row->oid);
 	rinfo->done++;
 
-	sd_eprintf("done:%"PRIu64" count:%"PRIu64", oid:%"PRIx64, rinfo->done,
-		   rinfo->count, row->oid);
+	sd_err("done:%"PRIu64" count:%"PRIu64", oid:%"PRIx64, rinfo->done,
+	       rinfo->count, row->oid);
 
 	if (rinfo->done < rinfo->count) {
 		recover_next_object(rinfo);
@@ -673,7 +671,7 @@ static uint64_t *fetch_object_list(struct sd_node *e, uint32_t epoch,
 	int ret;
 
 	addr_to_str(name, sizeof(name), e->nid.addr, 0);
-	sd_dprintf("%s %"PRIu32, name, e->nid.port);
+	sd_debug("%s %"PRIu32, name, e->nid.port);
 
 retry:
 	sd_init_req(&hdr, SD_OP_GET_OBJ_LIST);
@@ -689,16 +687,16 @@ retry:
 		buf = xrealloc(buf, buf_size);
 		goto retry;
 	default:
-		sd_printf(SDOG_ALERT, "cannot get object list from %s:%d", name,
-			  e->nid.port);
-		sd_printf(SDOG_ALERT, "some objects may be not recovered at "
-			  "epoch %d", epoch);
+		sd_alert("cannot get object list from %s:%d", name,
+			 e->nid.port);
+		sd_alert("some objects may be not recovered at epoch %d",
+			 epoch);
 		free(buf);
 		return NULL;
 	}
 
 	*nr_oids = rsp->data_length / sizeof(uint64_t);
-	sd_dprintf("%zu", *nr_oids);
+	sd_debug("%zu", *nr_oids);
 	return buf;
 }
 
@@ -719,8 +717,8 @@ static void screen_object_list(struct recovery_list_work *rlw,
 
 		nr_objs = get_obj_copy_number(oids[i], rw->cur_vinfo->nr_zones);
 		if (!nr_objs) {
-			sd_eprintf("ERROR: can not find copy number for object"
-				   " %" PRIx64, oids[i]);
+			sd_err("ERROR: can not find copy number for object %"
+			       PRIx64, oids[i]);
 			continue;
 		}
 		oid_to_vnodes(rw->cur_vinfo->vnodes, rw->cur_vinfo->nr_vnodes,
@@ -759,7 +757,7 @@ static void prepare_object_list(struct work *work)
 	if (node_is_gateway_only())
 		return;
 
-	sd_dprintf("%u", rw->epoch);
+	sd_debug("%u", rw->epoch);
 	wait_get_vdis_done();
 again:
 	/* We need to start at random node for better load balance */
@@ -768,7 +766,7 @@ again:
 		struct sd_node *node = cur + i;
 
 		if (uatomic_read(&next_rinfo)) {
-			sd_dprintf("go to the next recovery");
+			sd_debug("go to the next recovery");
 			return;
 		}
 
@@ -785,7 +783,7 @@ again:
 		goto again;
 	}
 
-	sd_dprintf("%"PRIu64, rlw->count);
+	sd_debug("%"PRIu64, rlw->count);
 }
 
 int start_recovery(struct vnode_info *cur_vinfo, struct vnode_info *old_vinfo,
@@ -816,7 +814,7 @@ int start_recovery(struct vnode_info *cur_vinfo, struct vnode_info *old_vinfo,
 		nrinfo = uatomic_xchg_ptr(&next_rinfo, rinfo);
 		if (nrinfo)
 			free_recovery_info(nrinfo);
-		sd_dprintf("recovery skipped");
+		sd_debug("recovery skipped");
 
 		/*
 		 * This is necesary to invoke run_next_rw when
diff --git a/sheep/request.c b/sheep/request.c
index bc2a3e7..bd69ea9 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -47,14 +47,14 @@ static void io_op_done(struct work *work)
 	case SD_RES_EIO:
 		req->rp.result = SD_RES_NETWORK_ERROR;
 
-		sd_eprintf("leaving sheepdog cluster");
+		sd_err("leaving sheepdog cluster");
 		leave_cluster();
 		break;
 	case SD_RES_SUCCESS:
 	case SD_RES_NETWORK_ERROR:
 		break;
 	default:
-		sd_dprintf("unhandled error %s", sd_strerror(req->rp.result));
+		sd_debug("unhandled error %s", sd_strerror(req->rp.result));
 		break;
 	}
 
@@ -110,13 +110,13 @@ static void gateway_op_done(struct work *work)
 	case SD_RES_WAIT_FOR_JOIN:
 	case SD_RES_WAIT_FOR_FORMAT:
 	case SD_RES_KILLED:
-		sd_dprintf("retrying failed I/O request op %s result %x epoch %"
-			   PRIu32", sys epoch %"PRIu32, op_name(req->op),
-			   req->rp.result, req->rq.epoch, sys->cinfo.epoch);
+		sd_debug("retrying failed I/O request op %s result %x epoch %"
+			 PRIu32 ", sys epoch %" PRIu32, op_name(req->op),
+			 req->rp.result, req->rq.epoch, sys->cinfo.epoch);
 		goto retry;
 	case SD_RES_EIO:
 		if (is_access_local(req, hdr->obj.oid)) {
-			sd_eprintf("leaving sheepdog cluster");
+			sd_err("leaving sheepdog cluster");
 			leave_cluster();
 			goto retry;
 		}
@@ -124,7 +124,7 @@ static void gateway_op_done(struct work *work)
 	case SD_RES_SUCCESS:
 		break;
 	default:
-		sd_dprintf("unhandled error %s", sd_strerror(req->rp.result));
+		sd_debug("unhandled error %s", sd_strerror(req->rp.result));
 		break;
 	}
 
@@ -149,16 +149,16 @@ static void local_op_done(struct work *work)
 static int check_request_epoch(struct request *req)
 {
 	if (before(req->rq.epoch, sys->cinfo.epoch)) {
-		sd_eprintf("old node version %u, %u (%s)",
-			   sys->cinfo.epoch, req->rq.epoch, op_name(req->op));
+		sd_err("old node version %u, %u (%s)", sys->cinfo.epoch,
+		       req->rq.epoch, op_name(req->op));
 		/* Ask for sleeping req on requester's wait queue */
 		req->rp.result = SD_RES_OLD_NODE_VER;
 		req->rp.epoch = sys->cinfo.epoch;
 		put_request(req);
 		return -1;
 	} else if (after(req->rq.epoch, sys->cinfo.epoch)) {
-		sd_eprintf("new node version %u, %u (%s)",
-			   sys->cinfo.epoch, req->rq.epoch, op_name(req->op));
+		sd_err("new node version %u, %u (%s)", sys->cinfo.epoch,
+		       req->rq.epoch, op_name(req->op));
 		/* Wait for local epoch to be lifted */
 		req->rp.result = SD_RES_NEW_NODE_VER;
 		sleep_on_wait_queue(req);
@@ -187,7 +187,7 @@ static bool request_in_recovery(struct request *req)
 	 */
 	if (oid_in_recovery(req->local_oid) &&
 	    !(req->rq.flags & SD_FLAG_CMD_RECOVERY)) {
-		sd_dprintf("%"PRIx64" wait on oid", req->local_oid);
+		sd_debug("%"PRIx64" wait on oid", req->local_oid);
 		sleep_on_wait_queue(req);
 		return true;
 	}
@@ -210,7 +210,7 @@ void wakeup_requests_on_epoch(void)
 			 * its epoch changes.
 			 */
 			assert(is_gateway_op(req->op));
-			sd_dprintf("gateway %"PRIx64, req->rq.obj.oid);
+			sd_debug("gateway %"PRIx64, req->rq.obj.oid);
 			req->rq.epoch = sys->cinfo.epoch;
 			del_requeue_request(req);
 			break;
@@ -220,7 +220,7 @@ void wakeup_requests_on_epoch(void)
 			 * changes.
 			 */
 			assert(!is_gateway_op(req->op));
-			sd_dprintf("peer %"PRIx64, req->rq.obj.oid);
+			sd_debug("peer %"PRIx64, req->rq.obj.oid);
 			del_requeue_request(req);
 			break;
 		default:
@@ -242,7 +242,7 @@ void wakeup_requests_on_oid(uint64_t oid)
 	list_for_each_entry_safe(req, t, &pending_list, request_list) {
 		if (req->local_oid != oid)
 			continue;
-		sd_dprintf("retry %" PRIx64, req->local_oid);
+		sd_debug("retry %" PRIx64, req->local_oid);
 		del_requeue_request(req);
 	}
 	list_splice_init(&pending_list, &sys->req_wait_queue);
@@ -256,7 +256,7 @@ void wakeup_all_requests(void)
 	list_splice_init(&sys->req_wait_queue, &pending_list);
 
 	list_for_each_entry_safe(req, n, &pending_list, request_list) {
-		sd_dprintf("%"PRIx64, req->rq.obj.oid);
+		sd_debug("%"PRIx64, req->rq.obj.oid);
 		del_requeue_request(req);
 	}
 }
@@ -339,12 +339,12 @@ static void queue_request(struct request *req)
 
 	req->op = get_sd_op(hdr->opcode);
 	if (!req->op) {
-		sd_eprintf("invalid opcode %d", hdr->opcode);
+		sd_err("invalid opcode %d", hdr->opcode);
 		rsp->result = SD_RES_INVALID_PARMS;
 		goto done;
 	}
 
-	sd_dprintf("%s, %d", op_name(req->op), sys->cinfo.status);
+	sd_debug("%s, %d", op_name(req->op), sys->cinfo.status);
 
 	switch (sys->cinfo.status) {
 	case SD_STATUS_KILLED:
@@ -380,7 +380,7 @@ static void queue_request(struct request *req)
 		hdr->epoch = sys->cinfo.epoch;
 		queue_cluster_request(req);
 	} else {
-		sd_eprintf("unknown operation %d", hdr->opcode);
+		sd_err("unknown operation %d", hdr->opcode);
 		rsp->result = SD_RES_SYSTEM_ERROR;
 		goto done;
 	}
@@ -565,7 +565,7 @@ static inline int begin_rx(struct client_info *ci)
 		ret = rx(conn, C_IO_END);
 		break;
 	default:
-		sd_eprintf("bug: unknown state %d", conn->c_rx_state);
+		sd_err("bug: unknown state %d", conn->c_rx_state);
 	}
 
 	if (is_conn_dead(conn)) {
@@ -587,7 +587,7 @@ static inline void finish_rx(struct client_info *ci)
 	req = ci->rx_req;
 	init_rx_hdr(ci);
 
-	sd_dprintf("%d, %s:%d", ci->conn.fd, ci->conn.ipstr, ci->conn.port);
+	sd_debug("%d, %s:%d", ci->conn.fd, ci->conn.ipstr, ci->conn.port);
 	queue_request(req);
 }
 
@@ -673,8 +673,8 @@ static inline int finish_tx(struct client_info *ci)
 {
 	/* Finish sending one response */
 	if (ci->conn.c_tx_state == C_IO_END) {
-		sd_dprintf("connection from: %d, %s:%d", ci->conn.fd,
-			   ci->conn.ipstr, ci->conn.port);
+		sd_debug("connection from: %d, %s:%d", ci->conn.fd,
+			 ci->conn.ipstr, ci->conn.port);
 		free_request(ci->tx_req);
 		ci->tx_req = NULL;
 	}
@@ -704,7 +704,7 @@ static void do_client_tx(struct client_info *ci)
 
 static void destroy_client(struct client_info *ci)
 {
-	sd_dprintf("connection from: %s:%d", ci->conn.ipstr, ci->conn.port);
+	sd_debug("connection from: %s:%d", ci->conn.ipstr, ci->conn.port);
 	close(ci->conn.fd);
 	free(ci);
 }
@@ -713,7 +713,7 @@ static void clear_client_info(struct client_info *ci)
 {
 	struct request *req, *t;
 
-	sd_dprintf("connection seems to be dead");
+	sd_debug("connection seems to be dead");
 
 	if (ci->rx_req) {
 		free_request(ci->rx_req);
@@ -732,8 +732,8 @@ static void clear_client_info(struct client_info *ci)
 
 	unregister_event(ci->conn.fd);
 
-	sd_dprintf("refcnt:%d, fd:%d, %s:%d", refcount_read(&ci->refcnt),
-		ci->conn.fd, ci->conn.ipstr, ci->conn.port);
+	sd_debug("refcnt:%d, fd:%d, %s:%d", refcount_read(&ci->refcnt),
+		 ci->conn.fd, ci->conn.ipstr, ci->conn.port);
 
 	if (refcount_read(&ci->refcnt))
 		return;
@@ -782,8 +782,8 @@ static void client_handler(int fd, int events, void *data)
 {
 	struct client_info *ci = (struct client_info *)data;
 
-	sd_dprintf("%x, rx %d, tx %d", events, ci->conn.c_rx_state,
-		   ci->conn.c_tx_state);
+	sd_debug("%x, rx %d, tx %d", events, ci->conn.c_rx_state,
+		 ci->conn.c_tx_state);
 
 	if (events & (EPOLLERR | EPOLLHUP) || is_conn_dead(&ci->conn))
 		return clear_client_info(ci);
@@ -804,7 +804,7 @@ static void listen_handler(int listen_fd, int events, void *data)
 	bool is_inet_socket = *(bool *)data;
 
 	if (sys->cinfo.status == SD_STATUS_SHUTDOWN) {
-		sd_dprintf("unregistering connection %d", listen_fd);
+		sd_debug("unregistering connection %d", listen_fd);
 		unregister_event(listen_fd);
 		return;
 	}
@@ -812,7 +812,7 @@ static void listen_handler(int listen_fd, int events, void *data)
 	namesize = sizeof(from);
 	fd = accept(listen_fd, (struct sockaddr *)&from, &namesize);
 	if (fd < 0) {
-		sd_eprintf("failed to accept a new connection: %m");
+		sd_err("failed to accept a new connection: %m");
 		return;
 	}
 
@@ -842,7 +842,7 @@ static void listen_handler(int listen_fd, int events, void *data)
 		return;
 	}
 
-	sd_dprintf("accepted a new connection: %d", fd);
+	sd_debug("accepted a new connection: %d", fd);
 }
 
 static int create_listen_port_fn(int fd, void *data)
@@ -876,7 +876,7 @@ static void local_req_handler(int listen_fd, int events, void *data)
 	LIST_HEAD(pending_list);
 
 	if (events & EPOLLERR)
-		sd_eprintf("request handler error");
+		sd_err("request handler error");
 
 	eventfd_xread(listen_fd);
 
@@ -913,13 +913,13 @@ worker_fn int sheep_exec_req(const struct node_id *nid, struct sd_req *hdr,
 	ret = exec_req(sfd->fd, hdr, buf, sheep_need_retry, hdr->epoch,
 		       MAX_RETRY_COUNT);
 	if (ret) {
-		sd_dprintf("remote node might have gone away");
+		sd_debug("remote node might have gone away");
 		sockfd_cache_del(nid, sfd);
 		return SD_RES_NETWORK_ERROR;
 	}
 	ret = rsp->result;
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("failed %s", sd_strerror(ret));
+		sd_err("failed %s", sd_strerror(ret));
 
 	sockfd_cache_put(nid, sfd);
 	return ret;
diff --git a/sheep/sheep.c b/sheep/sheep.c
index e750dbf..79551dd 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -209,13 +209,13 @@ static void signal_handler(int listen_fd, int events, void *data)
 
 	ret = read(sigfd, &siginfo, sizeof(siginfo));
 	assert(ret == sizeof(siginfo));
-	sd_dprintf("signal %d", siginfo.ssi_signo);
+	sd_debug("signal %d", siginfo.ssi_signo);
 	switch (siginfo.ssi_signo) {
 	case SIGTERM:
 		sys->cinfo.status = SD_STATUS_KILLED;
 		break;
 	default:
-		sd_eprintf("signal %d unhandled", siginfo.ssi_signo);
+		sd_err("signal %d unhandled", siginfo.ssi_signo);
 		break;
 	}
 }
@@ -231,25 +231,24 @@ static int init_signal(void)
 
 	sigfd = signalfd(-1, &mask, SFD_NONBLOCK);
 	if (sigfd < 0) {
-		sd_eprintf("failed to create a signal fd: %m");
+		sd_err("failed to create a signal fd: %m");
 		return -1;
 	}
 
 	ret = register_event(sigfd, signal_handler, NULL);
 	if (ret) {
-		sd_eprintf("failed to register signal handler (%d)", ret);
+		sd_err("failed to register signal handler (%d)", ret);
 		return -1;
 	}
 
-	sd_dprintf("register signal_handler for %d", sigfd);
+	sd_debug("register signal_handler for %d", sigfd);
 
 	return 0;
 }
 
 static void crash_handler(int signo)
 {
-	sd_printf(SDOG_EMERG, "sheep exits unexpectedly (%s).",
-		  strsignal(signo));
+	sd_emerg("sheep exits unexpectedly (%s).", strsignal(signo));
 
 	sd_backtrace();
 	sd_dump_variable(__sys);
@@ -455,23 +454,23 @@ static void check_host_env(void)
 	struct rlimit r;
 
 	if (getrlimit(RLIMIT_NOFILE, &r) < 0)
-		sd_eprintf("failed to get nofile %m");
+		sd_err("failed to get nofile %m");
 	/*
 	 * 1024 is default for NOFILE on most distributions, which is very
 	 * dangerous to run Sheepdog cluster.
 	 */
 	else if (r.rlim_cur == 1024)
-		sd_eprintf("WARN: Allowed open files 1024 too small, "
-			   "suggested %u", SD_RLIM_NOFILE);
+		sd_err("WARN: Allowed open files 1024 too small, suggested %u",
+		       SD_RLIM_NOFILE);
 	else if (r.rlim_cur < SD_RLIM_NOFILE)
-		sd_iprintf("Allowed open files %lu, suggested %u", r.rlim_cur,
-			   SD_RLIM_NOFILE);
+		sd_info("Allowed open files %lu, suggested %u", r.rlim_cur,
+			SD_RLIM_NOFILE);
 
 	if (getrlimit(RLIMIT_CORE, &r) < 0)
-		sd_dprintf("failed to get core %m");
+		sd_debug("failed to get core %m");
 	else if (r.rlim_cur < RLIM_INFINITY)
-		sd_dprintf("Allowed core file size %lu, suggested unlimited",
-			   r.rlim_cur);
+		sd_debug("Allowed core file size %lu, suggested unlimited",
+			 r.rlim_cur);
 
 	/*
 	 * Disable glibc's dynamic mmap threshold and set it as 512k.
@@ -516,8 +515,7 @@ static int lock_and_daemon(bool daemonize, const char *base_dir)
 		}
 
 		if (setsid() == -1) {
-			sd_eprintf("becoming a leader of a new session"
-				" failed: %m");
+			sd_err("becoming a leader of a new session failed: %m");
 			status = 1;
 			goto end;
 		}
@@ -526,7 +524,7 @@ static int lock_and_daemon(bool daemonize, const char *base_dir)
 		case 0:
 			break;
 		case -1:
-			sd_eprintf("fork() failed during daemonize: %m");
+			sd_err("fork() failed during daemonize: %m");
 			status = 1;
 			goto end;
 		default:
@@ -535,14 +533,14 @@ static int lock_and_daemon(bool daemonize, const char *base_dir)
 		}
 
 		if (chdir("/")) {
-			sd_eprintf("chdir to / failed: %m");
+			sd_err("chdir to / failed: %m");
 			status = 1;
 			goto end;
 		}
 
 		devnull_fd = open("/dev/null", O_RDWR);
 		if (devnull_fd < 0) {
-			sd_eprintf("opening /dev/null failed: %m");
+			sd_err("opening /dev/null failed: %m");
 			status = 1;
 			goto end;
 		}
@@ -550,7 +548,7 @@ static int lock_and_daemon(bool daemonize, const char *base_dir)
 
 	ret = lock_base_dir(base_dir);
 	if (ret < 0) {
-		sd_eprintf("locking directory: %s failed", base_dir);
+		sd_err("locking directory: %s failed", base_dir);
 		status = 1;
 		goto end;
 	}
@@ -803,7 +801,7 @@ int main(int argc, char **argv)
 
 	ret = create_cluster(port, zone, nr_vnodes, explicit_addr);
 	if (ret) {
-		sd_eprintf("failed to create sheepdog cluster");
+		sd_err("failed to create sheepdog cluster");
 		exit(1);
 	}
 
@@ -812,7 +810,7 @@ int main(int argc, char **argv)
 		if (!strlen(jpath))
 			/* internal journal */
 			memcpy(jpath, dir, strlen(dir));
-		sd_dprintf("%s, %zd, %d", jpath, jsize, jskip);
+		sd_debug("%s, %zd, %d", jpath, jsize, jskip);
 		ret = journal_file_init(jpath, jsize, jskip);
 		if (ret)
 			exit(1);
@@ -865,20 +863,19 @@ int main(int argc, char **argv)
 
 	free(dir);
 	check_host_env();
-	sd_printf(SDOG_INFO, "sheepdog daemon (version %s) started",
-		  PACKAGE_VERSION);
+	sd_info("sheepdog daemon (version %s) started", PACKAGE_VERSION);
 
 	while (sys->nr_outstanding_reqs != 0 ||
 	       (sys->cinfo.status != SD_STATUS_KILLED &&
 		sys->cinfo.status != SD_STATUS_SHUTDOWN))
 		event_loop(-1);
 
-	sd_printf(SDOG_INFO, "shutdown");
+	sd_info("shutdown");
 
 	leave_cluster();
 
 	if (uatomic_is_true(&sys->use_journal)) {
-		sd_iprintf("cleaning journal file");
+		sd_info("cleaning journal file");
 		clean_journal_file(jpath);
 	}
 
diff --git a/sheep/store.c b/sheep/store.c
index 4e218d8..8b5eca0 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -23,7 +23,7 @@ int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
 	time_t t;
 	char path[PATH_MAX], *buf;
 
-	sd_dprintf("update epoch: %d, %zu", epoch, nr_nodes);
+	sd_debug("update epoch: %d, %zu", epoch, nr_nodes);
 
 	/* Piggyback the epoch creation time for 'collie cluster info' */
 	time(&t);
@@ -51,31 +51,31 @@ static int do_epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len,
 	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
 	fd = open(path, O_RDONLY);
 	if (fd < 0) {
-		sd_eprintf("failed to open epoch %"PRIu32" log, %m", epoch);
+		sd_err("failed to open epoch %"PRIu32" log, %m", epoch);
 		goto err;
 	}
 
 	memset(&epoch_stat, 0, sizeof(epoch_stat));
 	ret = fstat(fd, &epoch_stat);
 	if (ret < 0) {
-		sd_eprintf("failed to stat epoch %"PRIu32" log, %m", epoch);
+		sd_err("failed to stat epoch %"PRIu32" log, %m", epoch);
 		goto err;
 	}
 
 	if (len < epoch_stat.st_size - sizeof(*timestamp)) {
-		sd_eprintf("invalid epoch %"PRIu32" log", epoch);
+		sd_err("invalid epoch %"PRIu32" log", epoch);
 		goto err;
 	}
 
 	ret = xread(fd, nodes, epoch_stat.st_size - sizeof(*timestamp));
 	if (ret < 0) {
-		sd_eprintf("failed to read epoch %"PRIu32" log, %m", epoch);
+		sd_err("failed to read epoch %"PRIu32" log, %m", epoch);
 		goto err;
 	}
 
 	/* Broken epoch, just ignore */
 	if (ret % sizeof(struct sd_node) != 0) {
-		sd_eprintf("invalid epoch %"PRIu32" log", epoch);
+		sd_err("invalid epoch %"PRIu32" log", epoch);
 		goto err;
 	}
 
@@ -84,7 +84,7 @@ static int do_epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len,
 	if (timestamp) {
 		ret = xread(fd, timestamp, sizeof(*timestamp));
 		if (ret != sizeof(*timestamp)) {
-			sd_eprintf("invalid epoch %"PRIu32" log", epoch);
+			sd_err("invalid epoch %"PRIu32" log", epoch);
 			goto err;
 		}
 	}
@@ -147,16 +147,16 @@ int lock_base_dir(const char *d)
 
 	fd = open(lock_path, O_WRONLY|O_CREAT, sd_def_fmode);
 	if (fd < 0) {
-		sd_eprintf("failed to open lock file %s (%m)", lock_path);
+		sd_err("failed to open lock file %s (%m)", lock_path);
 		ret = -1;
 		goto out;
 	}
 
 	if (lockf(fd, F_TLOCK, 1) < 0) {
 		if (errno == EACCES || errno == EAGAIN)
-			sd_eprintf("another sheep daemon is using %s", d);
+			sd_err("another sheep daemon is using %s", d);
 		else
-			sd_eprintf("unable to get base dir lock (%m)");
+			sd_err("unable to get base dir lock (%m)");
 		ret = -1;
 		goto out;
 	}
@@ -180,7 +180,7 @@ static inline int check_path_len(const char *path)
 {
 	int len = strlen(path);
 	if (len > PATH_MAX) {
-		sd_eprintf("insanely long object directory %s", path);
+		sd_err("insanely long object directory %s", path);
 		return -1;
 	}
 
@@ -226,7 +226,7 @@ static int init_obj_path(const char *base_path, char *argp)
 	} else {
 		do {
 			if (is_meta_store(p)) {
-				sd_eprintf("%s is meta-store, abort", p);
+				sd_err("%s is meta-store, abort", p);
 				return -1;
 			}
 			md_add_disk(p);
@@ -261,7 +261,7 @@ int init_store_driver(bool is_gateway)
 		 * If the driver name is not NUL terminated we are in deep
 		 * trouble, let's get out here.
 		 */
-		sd_dprintf("store name not NUL terminated");
+		sd_debug("store name not NUL terminated");
 		return SD_RES_NO_STORE;
 	}
 
@@ -274,7 +274,7 @@ int init_store_driver(bool is_gateway)
 
 	sd_store = find_store_driver(driver_name);
 	if (!sd_store) {
-		sd_dprintf("store %s not found", driver_name);
+		sd_debug("store %s not found", driver_name);
 		return SD_RES_NO_STORE;
 	}
 
@@ -314,7 +314,7 @@ int init_disk_space(const char *base_path)
 	} else {
 		ret = statvfs(base_path, &fs);
 		if (ret < 0) {
-			sd_dprintf("get disk space failed %m");
+			sd_debug("get disk space failed %m");
 			ret = SD_RES_EIO;
 			goto out;
 		}
@@ -323,7 +323,7 @@ int init_disk_space(const char *base_path)
 
 	ret = set_node_space(sys->disk_space);
 out:
-	sd_dprintf("disk free space is %" PRIu64, sys->disk_space);
+	sd_debug("disk free space is %" PRIu64, sys->disk_space);
 	return ret;
 }
 
@@ -359,8 +359,8 @@ int write_object(uint64_t oid, char *data, unsigned int datalen,
 			goto forward_write;
 
 		if (ret != 0) {
-			sd_eprintf("write cache failed %"PRIx64" %"PRIx32, oid,
-				   ret);
+			sd_err("write cache failed %" PRIx64 " %" PRIx32, oid,
+			       ret);
 			return ret;
 		}
 	}
@@ -379,7 +379,7 @@ forward_write:
 
 	ret = exec_local_req(&hdr, data);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("failed to write object %" PRIx64 ", %s", oid,
+		sd_err("failed to write object %" PRIx64 ", %s", oid,
 			   sd_strerror(ret));
 
 	return ret;
@@ -400,8 +400,8 @@ int read_backend_object(uint64_t oid, char *data, unsigned int datalen,
 
 	ret = exec_local_req(&hdr, data);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("failed to read object %" PRIx64 ", %s", oid,
-			   sd_strerror(ret));
+		sd_err("failed to read object %" PRIx64 ", %s", oid,
+		       sd_strerror(ret));
 
 	untrim_zero_blocks(data, rsp->obj.offset, rsp->data_length, datalen);
 
@@ -420,8 +420,8 @@ int read_object(uint64_t oid, char *data, unsigned int datalen,
 	if (sys->enable_object_cache && object_is_cached(oid)) {
 		ret = object_cache_read(oid, data, datalen, offset);
 		if (ret != SD_RES_SUCCESS) {
-			sd_eprintf("try forward read %"PRIx64" %s", oid,
-				   sd_strerror(ret));
+			sd_err("try forward read %" PRIx64 " %s", oid,
+			       sd_strerror(ret));
 			goto forward_read;
 		}
 		return ret;
@@ -448,8 +448,8 @@ int remove_object(uint64_t oid)
 
 	ret = exec_local_req(&hdr, NULL);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("failed to remove object %" PRIx64 ", %s", oid,
-			   sd_strerror(ret));
+		sd_err("failed to remove object %" PRIx64 ", %s", oid,
+		       sd_strerror(ret));
 
 	return ret;
 }
diff --git a/sheep/trace/checker.c b/sheep/trace/checker.c
index 90c8948..c3efc60 100644
--- a/sheep/trace/checker.c
+++ b/sheep/trace/checker.c
@@ -40,9 +40,8 @@ static void event_handler_exit(const struct caller *this_fn, int depth)
 		unsigned quot = duration / 1000, rem = duration % 1000;
 
 		if (quot > MAX_EVENT_DURATION)
-			sd_printf(SDOG_WARNING,
-				  "%s wastes too much time in event loop: "
-				  "%u.%-3u us", this_fn->name, quot, rem);
+			sd_warn("%s wastes too much time in event loop: "
+				"%u.%-3u us", this_fn->name, quot, rem);
 	}
 }
 
diff --git a/sheep/trace/trace.c b/sheep/trace/trace.c
index 813986c..1d3007b 100644
--- a/sheep/trace/trace.c
+++ b/sheep/trace/trace.c
@@ -179,10 +179,10 @@ int trace_enable(const char *name)
 	struct tracer *tracer = find_tracer(name);
 
 	if (tracer == NULL) {
-		sd_dprintf("no such tracer, %s", name);
+		sd_debug("no such tracer, %s", name);
 		return SD_RES_NO_SUPPORT;
 	} else if (uatomic_is_true(&tracer->enabled)) {
-		sd_dprintf("tracer %s is already enabled", name);
+		sd_debug("tracer %s is already enabled", name);
 		return SD_RES_INVALID_PARMS;
 	}
 
@@ -193,7 +193,7 @@ int trace_enable(const char *name)
 		patch_all_sites((unsigned long)trace_caller);
 		resume_worker_threads();
 	}
-	sd_dprintf("tracer %s enabled", tracer->name);
+	sd_debug("tracer %s enabled", tracer->name);
 
 	return SD_RES_SUCCESS;
 }
@@ -203,10 +203,10 @@ int trace_disable(const char *name)
 	struct tracer *tracer = find_tracer(name);
 
 	if (tracer == NULL) {
-		sd_dprintf("no such tracer, %s", name);
+		sd_debug("no such tracer, %s", name);
 		return SD_RES_NO_SUPPORT;
 	} else if (!uatomic_is_true(&tracer->enabled)) {
-		sd_dprintf("tracer %s is not enabled", name);
+		sd_debug("tracer %s is not enabled", name);
 		return SD_RES_INVALID_PARMS;
 	}
 
@@ -216,7 +216,7 @@ int trace_disable(const char *name)
 		nop_all_sites();
 		resume_worker_threads();
 	}
-	sd_dprintf("tracer %s disabled", tracer->name);
+	sd_debug("tracer %s disabled", tracer->name);
 
 	return SD_RES_SUCCESS;
 }
@@ -319,17 +319,17 @@ static bfd *get_bfd(void)
 
 	abfd = bfd_openr(fname, NULL);
 	if (abfd == 0) {
-		sd_eprintf("cannot open %s", fname);
+		sd_err("cannot open %s", fname);
 		return NULL;
 	}
 
 	if (!bfd_check_format(abfd, bfd_object)) {
-		sd_eprintf("invalid format");
+		sd_err("invalid format");
 		return NULL;
 	}
 
 	if (!(bfd_get_file_flags(abfd) & HAS_SYMS)) {
-		sd_eprintf("no symbols found");
+		sd_err("no symbols found");
 		return NULL;
 	}
 
@@ -350,7 +350,7 @@ static int init_callers(void)
 
 	max_symtab_size = bfd_get_symtab_upper_bound(abfd);
 	if (max_symtab_size < 0) {
-		sd_eprintf("failed to get symtab size");
+		sd_err("failed to get symtab size");
 		return -1;
 	}
 
@@ -371,7 +371,7 @@ static int init_callers(void)
 
 		ip = find_mcount_call(addr);
 		if (ip == 0) {
-			sd_dprintf("%s doesn't have mcount call", name);
+			sd_debug("%s doesn't have mcount call", name);
 			continue;
 		}
 		if (make_text_writable(ip) < 0)
@@ -417,6 +417,6 @@ int trace_init(void)
 		pthread_mutex_init(&buffer_lock[i], NULL);
 	}
 
-	sd_iprintf("trace support enabled. cpu count %d.", nr_cpu);
+	sd_info("trace support enabled. cpu count %d.", nr_cpu);
 	return 0;
 }
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 24c0ef0..c957059 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -75,7 +75,7 @@ static bool vid_is_snapshot(uint32_t vid)
 	sd_unlock(&vdi_state_lock);
 
 	if (!entry) {
-		sd_eprintf("No VDI entry for %" PRIx32 " found", vid);
+		sd_err("No VDI entry for %" PRIx32 " found", vid);
 		return 0;
 	}
 
@@ -100,7 +100,7 @@ int get_vdi_copy_number(uint32_t vid)
 	sd_unlock(&vdi_state_lock);
 
 	if (!entry) {
-		sd_eprintf("No VDI copy entry for %" PRIx32 " found", vid);
+		sd_err("No VDI copy entry for %" PRIx32 " found", vid);
 		return 0;
 	}
 
@@ -143,7 +143,7 @@ int add_vdi_state(uint32_t vid, int nr_copies, bool snapshot)
 	entry->nr_copies = nr_copies;
 	entry->snapshot = snapshot;
 
-	sd_dprintf("%" PRIx32 ", %d", vid, nr_copies);
+	sd_debug("%" PRIx32 ", %d", vid, nr_copies);
 
 	sd_write_lock(&vdi_state_lock);
 	old = vdi_state_insert(&vdi_state_root, entry);
@@ -198,7 +198,7 @@ int vdi_exist(uint32_t vid)
 	ret = read_object(vid_to_vdi_oid(vid), (char *)inode,
 			  sizeof(*inode), 0);
 	if (ret != SD_RES_SUCCESS) {
-		sd_eprintf("fail to read vdi inode (%" PRIx32 ")", vid);
+		sd_err("fail to read vdi inode (%" PRIx32 ")", vid);
 		ret = 0;
 		goto out;
 	}
@@ -244,13 +244,13 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 
 	if (iocb->create_snapshot) {
 		if (cur_vid != iocb->base_vid) {
-			sd_printf(SDOG_INFO, "tree snapshot %s %" PRIx32 " %"
-				  PRIx32, name, cur_vid, iocb->base_vid);
+			sd_info("tree snapshot %s %" PRIx32 " %" PRIx32, name,
+				cur_vid, iocb->base_vid);
 
 			ret = read_object(vid_to_vdi_oid(cur_vid), (char *)cur,
 					  SD_INODE_HEADER_SIZE, 0);
 			if (ret != SD_RES_SUCCESS) {
-				sd_printf(SDOG_ERR, "failed");
+				sd_err("failed");
 				ret = SD_RES_BASE_VDI_READ;
 				goto out;
 			}
@@ -292,7 +292,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 		ret = write_object(vid_to_vdi_oid(cur_vid), (char *)cur,
 				   SD_INODE_HEADER_SIZE, 0, false);
 		if (ret != 0) {
-			sd_printf(SDOG_ERR, "failed");
+			sd_err("failed");
 			ret = SD_RES_BASE_VDI_READ;
 			goto out;
 		}
@@ -302,7 +302,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 		ret = write_object(vid_to_vdi_oid(iocb->base_vid), (char *)base,
 				   SD_INODE_HEADER_SIZE, 0, false);
 		if (ret != 0) {
-			sd_printf(SDOG_ERR, "failed");
+			sd_err("failed");
 			ret = SD_RES_BASE_VDI_WRITE;
 			goto out;
 		}
@@ -378,7 +378,7 @@ static int fill_vdi_info_range(uint32_t left, uint32_t right,
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
-		sd_eprintf("failed to allocate memory");
+		sd_err("failed to allocate memory");
 		ret = SD_RES_NO_MEM;
 		goto out;
 	}
@@ -396,8 +396,8 @@ static int fill_vdi_info_range(uint32_t left, uint32_t right,
 		}
 
 		if (!strncmp(inode->name, name, strlen(inode->name))) {
-			sd_dprintf("%s = %s, %u = %u", iocb->tag, inode->tag,
-				   iocb->snapid, inode->snap_id);
+			sd_debug("%s = %s, %u = %u", iocb->tag, inode->tag,
+				 iocb->snapid, inode->snap_id);
 			if (vdi_has_tag(iocb)) {
 				/* Read, delete, clone on snapshots */
 				if (!vdi_is_snapshot(inode)) {
@@ -457,7 +457,7 @@ int vdi_lookup(struct vdi_iocb *iocb, struct vdi_info *info)
 
 	ret = get_vdi_bitmap_range(iocb->name, &left, &right);
 	info->free_bit = right;
-	sd_dprintf("%s left %lx right %lx, %x", iocb->name, left, right, ret);
+	sd_debug("%s left %lx right %lx, %x", iocb->name, left, right, ret);
 	switch (ret) {
 	case SD_RES_NO_VDI:
 	case SD_RES_FULL_VDI:
@@ -481,8 +481,8 @@ static int notify_vdi_add(uint32_t vdi_id, uint32_t nr_copies, uint32_t old_vid)
 
 	ret = exec_local_req(&hdr, NULL);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("fail to notify vdi add event(%" PRIx32 ", %d, %"
-			   PRIx32 ")", vdi_id, nr_copies, old_vid);
+		sd_err("fail to notify vdi add event(%" PRIx32 ", %d, %" PRIx32
+		       ")", vdi_id, nr_copies, old_vid);
 
 	return ret;
 }
@@ -497,8 +497,8 @@ static void vdi_flush(uint32_t vid)
 
 	ret = exec_local_req(&hdr, NULL);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("fail to flush vdi %" PRIx32 ", %s", vid,
-			   sd_strerror(ret));
+		sd_err("fail to flush vdi %" PRIx32 ", %s", vid,
+		       sd_strerror(ret));
 }
 
 /*
@@ -529,7 +529,7 @@ int vdi_create(struct vdi_iocb *iocb, uint32_t *new_vid)
 			return ret;
 		break;
 	default:
-		sd_eprintf("%s", sd_strerror(ret));
+		sd_err("%s", sd_strerror(ret));
 		return ret;
 	}
 	if (!iocb->snapid)
@@ -539,11 +539,11 @@ int vdi_create(struct vdi_iocb *iocb, uint32_t *new_vid)
 	if (ret != SD_RES_SUCCESS)
 		return ret;
 
-	sd_dprintf("%s %s: size %" PRIu64 ", vid %" PRIx32 ", base %" PRIx32
-		   ", cur %" PRIx32 ", copies %d, snapid %"PRIu32,
-		   iocb->create_snapshot ? "snapshot" : "vdi", name, iocb->size,
-		   *new_vid, iocb->base_vid, info.vid, iocb->nr_copies,
-		   iocb->snapid);
+	sd_debug("%s %s: size %" PRIu64 ", vid %" PRIx32 ", base %" PRIx32
+		 ", cur %" PRIx32 ", copies %d, snapid %" PRIu32,
+		 iocb->create_snapshot ? "snapshot" : "vdi", name, iocb->size,
+		 *new_vid, iocb->base_vid, info.vid, iocb->nr_copies,
+		 iocb->snapid);
 
 	return create_vdi_obj(iocb, *new_vid, info.vid);
 }
@@ -628,8 +628,8 @@ static int notify_vdi_deletion(uint32_t vdi_id)
 
 	ret = exec_local_req(&hdr, &vdi_id);
 	if (ret != SD_RES_SUCCESS)
-		sd_eprintf("fail to notify vdi deletion(%" PRIx32 "), %d",
-			   vdi_id, ret);
+		sd_err("fail to notify vdi deletion(%" PRIx32 "), %d", vdi_id,
+		       ret);
 
 	return ret;
 }
@@ -641,11 +641,11 @@ static void delete_one(struct work *work)
 	int ret, i, nr_deleted;
 	struct sd_inode *inode = NULL;
 
-	sd_dprintf("%d %d, %16x", dw->done, dw->count, vdi_id);
+	sd_debug("%d %d, %16x", dw->done, dw->count, vdi_id);
 
 	inode = malloc(sizeof(*inode));
 	if (!inode) {
-		sd_eprintf("failed to allocate memory");
+		sd_err("failed to allocate memory");
 		return;
 	}
 
@@ -653,7 +653,7 @@ static void delete_one(struct work *work)
 			  (void *)inode, sizeof(*inode), 0);
 
 	if (ret != SD_RES_SUCCESS) {
-		sd_eprintf("cannot find VDI object");
+		sd_err("cannot find VDI object");
 		goto out;
 	}
 
@@ -669,15 +669,14 @@ static void delete_one(struct work *work)
 		oid = vid_to_data_oid(inode->data_vdi_id[i], i);
 
 		if (inode->data_vdi_id[i] != inode->vdi_id) {
-			sd_dprintf("object %" PRIx64 " is base's data, would"
-				   " not be deleted.", oid);
+			sd_debug("object %" PRIx64 " is base's data, would"
+				 " not be deleted.", oid);
 			continue;
 		}
 
 		ret = remove_object(oid);
 		if (ret != SD_RES_SUCCESS)
-			sd_eprintf("remove object %" PRIx64 " fail, %d", oid,
-				   ret);
+			sd_err("remove object %" PRIx64 " fail, %d", oid, ret);
 
 		nr_deleted++;
 	}
@@ -732,7 +731,7 @@ static int fill_vdi_list(struct deletion_work *dw, uint32_t root_vid)
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
-		sd_eprintf("failed to allocate memory");
+		sd_err("failed to allocate memory");
 		goto err;
 	}
 
@@ -743,7 +742,7 @@ again:
 			  SD_INODE_HEADER_SIZE, 0);
 
 	if (ret != SD_RES_SUCCESS) {
-		sd_eprintf("cannot find VDI object");
+		sd_err("cannot find VDI object");
 		goto err;
 	}
 
@@ -776,7 +775,7 @@ static uint64_t get_vdi_root(uint32_t vid, bool *cloned)
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
-		sd_eprintf("failed to allocate memory");
+		sd_err("failed to allocate memory");
 		vid = 0;
 		goto out;
 	}
@@ -787,13 +786,13 @@ next:
 	if (vid == inode->vdi_id && inode->snap_id == 1
 			&& inode->parent_vdi_id != 0
 			&& !inode->snap_ctime) {
-		sd_dprintf("vdi %" PRIx32 " is a cloned vdi.", vid);
+		sd_debug("vdi %" PRIx32 " is a cloned vdi.", vid);
 		/* current vdi is a cloned vdi */
 		*cloned = true;
 	}
 
 	if (ret != SD_RES_SUCCESS) {
-		sd_eprintf("cannot find VDI object");
+		sd_err("cannot find VDI object");
 		vid = 0;
 		goto out;
 	}
@@ -843,15 +842,14 @@ static int start_deletion(struct request *req, uint32_t vid)
 			dw->buf[0] = vid;
 			dw->count = 1;
 		} else {
-			sd_dprintf("snapshot chain has valid vdi, "
-				   "just mark vdi %" PRIx32 " as deleted.",
-				   dw->vid);
+			sd_debug("snapshot chain has valid vdi, just mark vdi %"
+				 PRIx32 " as deleted.", dw->vid);
 			delete_inode(dw);
 			return SD_RES_SUCCESS;
 		}
 	}
 
-	sd_dprintf("%d", dw->count);
+	sd_debug("%d", dw->count);
 
 	if (dw->count == 0)
 		goto out;
@@ -942,7 +940,7 @@ int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,
 		(*attrid)++;
 	}
 
-	sd_dprintf("there is no space for new VDIs");
+	sd_debug("there is no space for new VDIs");
 	ret = SD_RES_FULL_VDI;
 out:
 	return ret;
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index 7c96796..2acbffd 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -104,8 +104,8 @@ static int remove_efd;
 
 static inline void remove_sheep(struct sheep *sheep)
 {
-	sd_dprintf("remove_sheep() called, removing %s",
-		node_to_str(&sheep->node));
+	sd_debug("remove_sheep() called, removing %s",
+		 node_to_str(&sheep->node));
 
 	sheep->state = SHEEP_STATE_LEAVING;
 	eventfd_xwrite(remove_efd, 1);
@@ -130,7 +130,7 @@ static int notify_remove_sheep(struct sheep *leaving)
 			&leaving->node, sizeof(struct sd_node));
 
 		if (sizeof(snd) + sizeof(struct sd_node) != ret) {
-			sd_eprintf("writev2() failed: %m");
+			sd_err("writev2() failed: %m");
 
 			remove_sheep(s);
 			failed++;
@@ -147,14 +147,13 @@ static void remove_handler(int fd, int events, void *data)
 
 	nr_removed = eventfd_xread(remove_efd);
 
-	sd_dprintf("removed sheeps");
+	sd_debug("removed sheeps");
 remove:
 	list_for_each_entry(s, &sheep_list_head, sheep_list) {
 		if (s->state != SHEEP_STATE_LEAVING)
 			continue;
 
-		sd_printf(SDOG_DEBUG, "removing the node: %s",
-			node_to_str(&s->node));
+		sd_debug("removing the node: %s", node_to_str(&s->node));
 
 		if (!is_sd_node_zero(&s->node))
 			/*
@@ -176,7 +175,7 @@ remove:
 	goto end;
 
 del:
-	sd_iprintf("removed node: %s", node_to_str(&s->node));
+	sd_info("removed node: %s", node_to_str(&s->node));
 
 	unregister_event(s->fd);
 	close(s->fd);
@@ -191,7 +190,7 @@ del:
 		goto remove;
 
 end:
-	sd_dprintf("nodes which failed during remove_handler(): %d", failed);
+	sd_debug("nodes which failed during remove_handler(): %d", failed);
 }
 
 static LIST_HEAD(join_wait_queue);
@@ -217,10 +216,10 @@ retry:
 
 	wbytes = xwrite(waiting->fd, &snd, sizeof(snd));
 	if (sizeof(snd) != wbytes) {
-		sd_printf(SDOG_ERR, "xwrite() failed: %m");
+		sd_err("xwrite() failed: %m");
 		remove_sheep(waiting);
 
-		sd_iprintf("node %s is failed to join",
+		sd_info("node %s is failed to join",
 			node_to_str(&waiting->node));
 		nr_failed++;
 
@@ -244,21 +243,21 @@ static void sph_handle_join(struct sph_msg *msg, struct sheep *sheep)
 		buf = xzalloc(msg->body_len);
 		rbytes = xread(fd, buf, msg->body_len);
 		if (rbytes != msg->body_len) {
-			sd_eprintf("xread() failed: %m");
+			sd_err("xread() failed: %m");
 			goto purge_current_sheep;
 		}
 		free(buf);
 
 		list_add(&sheep->join_wait_list, &join_wait_queue);
 
-		sd_dprintf("there is already a joining sheep");
+		sd_debug("there is already a joining sheep");
 		return;
 	}
 
 	join = xzalloc(msg->body_len);
 	rbytes = xread(fd, join, msg->body_len);
 	if (msg->body_len != rbytes) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		free(join);
 		goto purge_current_sheep;
 	}
@@ -279,7 +278,7 @@ static void sph_handle_join(struct sph_msg *msg, struct sheep *sheep)
 	free(join);
 
 	if (sizeof(snd) + msg->body_len != wbytes) {
-		sd_eprintf("writev2() failed: %m");
+		sd_err("writev2() failed: %m");
 
 		goto purge_current_sheep;
 	}
@@ -305,18 +304,18 @@ static void sph_handle_accept(struct sph_msg *msg, struct sheep *sheep)
 	struct sph_msg_join_reply *join_reply_body;
 	struct sph_msg_join_node_finish *join_node_finish;
 
-	sd_dprintf("new node reply from %s", node_to_str(&sheep->node));
+	sd_debug("new node reply from %s", node_to_str(&sheep->node));
 
 	join = xzalloc(msg->body_len);
 	rbytes = xread(fd, join, msg->body_len);
 	if (msg->body_len != rbytes) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		free(join);
 
 		goto purge_current_sheep;
 	}
 
-	sd_dprintf("joining node is %s", node_to_str(&join->new_node));
+	sd_debug("joining node is %s", node_to_str(&join->new_node));
 
 	joining_sheep = find_sheep_by_nid(&join->new_node.nid);
 	assert(joining_sheep != NULL);
@@ -325,7 +324,7 @@ static void sph_handle_accept(struct sph_msg *msg, struct sheep *sheep)
 	opaque = xzalloc(opaque_len);
 	memcpy(opaque, join->opaque, opaque_len);
 
-	sd_printf(SDOG_DEBUG, "length of opaque: %d", opaque_len);
+	sd_debug("length of opaque: %d", opaque_len);
 	memset(&snd, 0, sizeof(snd));
 	snd.type = SPH_SRV_MSG_JOIN_REPLY;
 	snd.body_len = sizeof(struct sph_msg_join_reply) + opaque_len;
@@ -347,7 +346,7 @@ static void sph_handle_accept(struct sph_msg *msg, struct sheep *sheep)
 	free(join);
 
 	if (sizeof(snd) + snd.body_len != wbytes) {
-		sd_eprintf("writev2() to master failed: %m");
+		sd_err("writev2() to master failed: %m");
 
 		goto purge_current_sheep;
 	}
@@ -372,7 +371,7 @@ static void sph_handle_accept(struct sph_msg *msg, struct sheep *sheep)
 		wbytes = writev2(s->fd, &snd, join_node_finish, snd.body_len);
 
 		if (sizeof(snd) + snd.body_len != wbytes) {
-			sd_eprintf("writev2() failed: %m");
+			sd_err("writev2() failed: %m");
 			remove_sheep(s);
 			removed++;
 		}
@@ -408,7 +407,7 @@ static void sph_handle_notify(struct sph_msg *msg, struct sheep *sheep)
 	notify = xzalloc(msg->body_len);
 	rbytes = xread(fd, notify, msg->body_len);
 	if (rbytes != msg->body_len) {
-		sd_eprintf("xread() failed: %m");
+		sd_err("xread() failed: %m");
 		goto purge_current_sheep;
 	}
 
@@ -431,7 +430,7 @@ static void sph_handle_notify(struct sph_msg *msg, struct sheep *sheep)
 
 		wbytes = writev2(s->fd, &snd, notify_forward, snd.body_len);
 		if (sizeof(snd) + snd.body_len != wbytes) {
-			sd_eprintf("writev2() failed: %m");
+			sd_err("writev2() failed: %m");
 			goto notify_failed;
 		}
 
@@ -468,7 +467,7 @@ static void sph_handle_block(struct sph_msg *msg, struct sheep *sheep)
 		wbytes = writev2(s->fd, &snd,
 				&sheep->node, sizeof(struct sd_node));
 		if (sizeof(snd) + sizeof(struct sd_node) != wbytes) {
-			sd_eprintf("writev2() failed: %m");
+			sd_err("writev2() failed: %m");
 			goto block_failed;
 		}
 
@@ -487,7 +486,7 @@ static void sph_handle_leave(struct sph_msg *msg, struct sheep *sheep)
 	struct sheep *s;
 	struct sph_msg snd;
 
-	sd_iprintf("%s is leaving", node_to_str(&sheep->node));
+	sd_info("%s is leaving", node_to_str(&sheep->node));
 
 	memset(&snd, 0, sizeof(snd));
 	snd.type = SPH_SRV_MSG_LEAVE_FORWARD;
@@ -502,7 +501,7 @@ static void sph_handle_leave(struct sph_msg *msg, struct sheep *sheep)
 		wbytes = writev2(s->fd, &snd,
 				&sheep->node, sizeof(struct sd_node));
 		if (sizeof(snd) + sizeof(struct sd_node) != wbytes) {
-			sd_eprintf("writev2() failed: %m");
+			sd_err("writev2() failed: %m");
 			goto fwd_leave_failed;
 		}
 
@@ -530,26 +529,25 @@ static void read_msg_from_sheep(struct sheep *sheep)
 	ret = xread(sheep->fd, &rcv, sizeof(rcv));
 
 	if (ret != sizeof(rcv)) {
-		sd_eprintf("xread() failed: %m, ");
+		sd_err("xread() failed: %m, ");
 		goto remove;
 	}
 
 	if (!(0 <= rcv.type && rcv.type < ARRAY_SIZE(msg_handlers))) {
-		sd_eprintf("invalid message type: %d, ", rcv.type);
-		sd_eprintf("from node: %s", node_to_str(&sheep->node));
-		sd_eprintf("from node (sockaddr): %s",
-			sockaddr_in_to_str(&sheep->addr));
-		sd_eprintf("read bytes: %d, body length: %d",
-			ret, rcv.body_len);
+		sd_err("invalid message type: %d, ", rcv.type);
+		sd_err("from node: %s", node_to_str(&sheep->node));
+		sd_err("from node (sockaddr): %s",
+		       sockaddr_in_to_str(&sheep->addr));
+		sd_err("read bytes: %d, body length: %d", ret, rcv.body_len);
 		goto remove;
 	}
 
-	sd_dprintf("received op: %s", sph_cli_msg_to_str(rcv.type));
+	sd_debug("received op: %s", sph_cli_msg_to_str(rcv.type));
 
 	return msg_handlers[rcv.type](&rcv, sheep);
 
 remove:
-	sd_eprintf("removing node: %s", node_to_str(&sheep->node));
+	sd_err("removing node: %s", node_to_str(&sheep->node));
 	remove_sheep(sheep);
 }
 
@@ -558,8 +556,8 @@ static void sheep_comm_handler(int fd, int events, void *data)
 	if (events & EPOLLIN)
 		read_msg_from_sheep(data);
 	else if (events & EPOLLHUP || events & EPOLLERR) {
-		sd_eprintf("epoll() error: %s",
-			node_to_str(&((struct sheep *)data)->node));
+		sd_err("epoll() error: %s",
+		       node_to_str(&((struct sheep *)data)->node));
 		remove_sheep(data);
 	}
 }
@@ -576,18 +574,18 @@ static void sheep_accept_handler(int fd, int events, void *data)
 	len = sizeof(struct sockaddr_in);
 	new_sheep->fd = accept(fd, (struct sockaddr *)&new_sheep->addr, &len);
 	if (new_sheep->fd < 0) {
-		sd_eprintf("accept() failed: %m");
+		sd_err("accept() failed: %m");
 		goto clean;
 	}
 
 	if (-1 == set_keepalive(new_sheep->fd)) {
-		sd_eprintf("set_keepalive() failed: %m");
+		sd_err("set_keepalive() failed: %m");
 		goto clean;
 	}
 
 	ret = register_event(new_sheep->fd, sheep_comm_handler, new_sheep);
 	if (ret < 0) {
-		sd_eprintf("register_event() failed: %m");
+		sd_err("register_event() failed: %m");
 		goto clean;
 	}
 
@@ -596,7 +594,7 @@ static void sheep_accept_handler(int fd, int events, void *data)
 
 	INIT_LIST_HEAD(&new_sheep->join_wait_list);
 
-	sd_iprintf("accepted new sheep connection");
+	sd_info("accepted new sheep connection");
 	return;
 
 clean:
@@ -632,7 +630,7 @@ static void usage(void)
 
 static void exit_handler(void)
 {
-	sd_printf(SDOG_INFO, "exiting...");
+	sd_info("exiting...");
 }
 
 static int set_listen_fd_cb(int fd, void *data)
@@ -648,8 +646,7 @@ static int set_listen_fd_cb(int fd, void *data)
 
 static void crash_handler(int signo)
 {
-	sd_printf(SDOG_EMERG, "shepherd exits unexpectedly (%s).",
-		  strsignal(signo));
+	sd_emerg("shepherd exits unexpectedly (%s).", strsignal(signo));
 
 	sd_backtrace();
 
-- 
1.7.9.5



More information about the sheepdog mailing list