[RFC,1/1] vhost: Add dynamic logging system
diff mbox series

Message ID 20191018082638.4463-2-amorenoz@redhat.com
State New
Delegated to: Maxime Coquelin
Headers show
Series
  • vhost: Add dynamic log tracing
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK

Commit Message

Adrian Moreno Oct. 18, 2019, 8:26 a.m. UTC
Currently there are a couple of limitations on the logging system: Most
of the logs are compiled out and both datapath and controlpath logs
share the same loglevel.

This patch tries to help fix that situation by:
- Splitting control plane and data plane logs
- Making control plane logs dynamic while keeping data plane logs
compiled out by default for log levels lower than RTE_LOG_DP_LEVEL.

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
Fixes: 1c01d52392d5 ("vhost: add debug print")
Cc: huawei.xie@intel.com
Cc: maxime.coquelin@redhat.com

---
 lib/librte_vhost/iotlb.c      |  10 +--
 lib/librte_vhost/socket.c     |  76 ++++++++--------
 lib/librte_vhost/vhost.c      |  30 +++++--
 lib/librte_vhost/vhost.h      |  24 ++++--
 lib/librte_vhost/vhost_user.c | 158 +++++++++++++++++-----------------
 lib/librte_vhost/virtio_net.c |  40 ++++-----
 6 files changed, 179 insertions(+), 159 deletions(-)

Comments

Tiwei Bie Oct. 29, 2019, 1:45 p.m. UTC | #1
On Fri, Oct 18, 2019 at 10:26:39AM +0200, Adrian Moreno wrote:
> Currently there are a couple of limitations on the logging system: Most
> of the logs are compiled out and both datapath and controlpath logs
> share the same loglevel.
> 
> This patch tries to help fix that situation by:
> - Splitting control plane and data plane logs
> - Making control plane logs dynamic while keeping data plane logs
> compiled out by default for log levels lower than RTE_LOG_DP_LEVEL.

+1
Thanks for the work!

Thanks,
Tiwei

Patch
diff mbox series

diff --git a/lib/librte_vhost/iotlb.c b/lib/librte_vhost/iotlb.c
index 4a1d8c125..bc1758528 100644
--- a/lib/librte_vhost/iotlb.c
+++ b/lib/librte_vhost/iotlb.c
@@ -70,14 +70,14 @@  vhost_user_iotlb_pending_insert(struct vhost_virtqueue *vq,
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 	if (ret) {
-		RTE_LOG(DEBUG, VHOST_CONFIG, "IOTLB pool empty, clear entries\n");
+		VHOST_LOG_CONFIG(DEBUG, "IOTLB pool empty, clear entries\n");
 		if (!TAILQ_EMPTY(&vq->iotlb_pending_list))
 			vhost_user_iotlb_pending_remove_all(vq);
 		else
 			vhost_user_iotlb_cache_random_evict(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&node);
 		if (ret) {
-			RTE_LOG(ERR, VHOST_CONFIG, "IOTLB pool still empty, failure\n");
+			VHOST_LOG_CONFIG(ERR, "IOTLB pool still empty, failure\n");
 			return;
 		}
 	}
@@ -163,14 +163,14 @@  vhost_user_iotlb_cache_insert(struct vhost_virtqueue *vq, uint64_t iova,
 
 	ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 	if (ret) {
-		RTE_LOG(DEBUG, VHOST_CONFIG, "IOTLB pool empty, clear entries\n");
+		VHOST_LOG_CONFIG(DEBUG, "IOTLB pool empty, clear entries\n");
 		if (!TAILQ_EMPTY(&vq->iotlb_list))
 			vhost_user_iotlb_cache_random_evict(vq);
 		else
 			vhost_user_iotlb_pending_remove_all(vq);
 		ret = rte_mempool_get(vq->iotlb_pool, (void **)&new_node);
 		if (ret) {
-			RTE_LOG(ERR, VHOST_CONFIG, "IOTLB pool still empty, failure\n");
+			VHOST_LOG_CONFIG(ERR, "IOTLB pool still empty, failure\n");
 			return;
 		}
 	}
@@ -323,7 +323,7 @@  vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 			MEMPOOL_F_SP_PUT |
 			MEMPOOL_F_SC_GET);
 	if (!vq->iotlb_pool) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"Failed to create IOTLB cache pool (%s)\n",
 				pool_name);
 		return -1;
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 274988c4d..e08d6924b 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -125,12 +125,12 @@  read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
 
 	ret = recvmsg(sockfd, &msgh, 0);
 	if (ret <= 0) {
-		RTE_LOG(ERR, VHOST_CONFIG, "recvmsg failed\n");
+		VHOST_LOG_CONFIG(ERR, "recvmsg failed\n");
 		return ret;
 	}
 
 	if (msgh.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
-		RTE_LOG(ERR, VHOST_CONFIG, "truncted msg\n");
+		VHOST_LOG_CONFIG(ERR, "truncted msg\n");
 		return -1;
 	}
 
@@ -175,7 +175,7 @@  send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)
 		msgh.msg_controllen = sizeof(control);
 		cmsg = CMSG_FIRSTHDR(&msgh);
 		if (cmsg == NULL) {
-			RTE_LOG(ERR, VHOST_CONFIG, "cmsg == NULL\n");
+			VHOST_LOG_CONFIG(ERR, "cmsg == NULL\n");
 			errno = EINVAL;
 			return -1;
 		}
@@ -193,7 +193,7 @@  send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)
 	} while (ret < 0 && errno == EINTR);
 
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,  "sendmsg error\n");
+		VHOST_LOG_CONFIG(ERR,  "sendmsg error\n");
 		return ret;
 	}
 
@@ -232,12 +232,12 @@  vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 	if (vsocket->dequeue_zero_copy)
 		vhost_enable_dequeue_zero_copy(vid);
 
-	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
+	VHOST_LOG_CONFIG(INFO, "new device, handle is %d\n", vid);
 
 	if (vsocket->notify_ops->new_connection) {
 		ret = vsocket->notify_ops->new_connection(vid);
 		if (ret < 0) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"failed to add vhost user connection with fd %d\n",
 				fd);
 			goto err_cleanup;
@@ -250,7 +250,7 @@  vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 	ret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb,
 			NULL, conn);
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"failed to add fd %d into vhost server fdset\n",
 			fd);
 
@@ -284,7 +284,7 @@  vhost_user_server_new_connection(int fd, void *dat, int *remove __rte_unused)
 	if (fd < 0)
 		return;
 
-	RTE_LOG(INFO, VHOST_CONFIG, "new vhost user connection is %d\n", fd);
+	VHOST_LOG_CONFIG(INFO, "new vhost user connection is %d\n", fd);
 	vhost_user_add_connection(fd, vsocket);
 }
 
@@ -332,11 +332,11 @@  create_unix_socket(struct vhost_user_socket *vsocket)
 	fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (fd < 0)
 		return -1;
-	RTE_LOG(INFO, VHOST_CONFIG, "vhost-user %s: socket created, fd: %d\n",
+	VHOST_LOG_CONFIG(INFO, "vhost-user %s: socket created, fd: %d\n",
 		vsocket->is_server ? "server" : "client", fd);
 
 	if (!vsocket->is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"vhost-user: can't set nonblocking mode for socket, fd: "
 			"%d (%s)\n", fd, strerror(errno));
 		close(fd);
@@ -371,12 +371,12 @@  vhost_user_start_server(struct vhost_user_socket *vsocket)
 	 */
 	ret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un));
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"failed to bind to %s: %s; remove it and try again\n",
 			path, strerror(errno));
 		goto err;
 	}
-	RTE_LOG(INFO, VHOST_CONFIG, "bind to %s\n", path);
+	VHOST_LOG_CONFIG(INFO, "bind to %s\n", path);
 
 	ret = listen(fd, MAX_VIRTIO_BACKLOG);
 	if (ret < 0)
@@ -385,7 +385,7 @@  vhost_user_start_server(struct vhost_user_socket *vsocket)
 	ret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,
 		  NULL, vsocket);
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"failed to add listen fd %d to vhost server fdset\n",
 			fd);
 		goto err;
@@ -426,12 +426,12 @@  vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz)
 
 	flags = fcntl(fd, F_GETFL, 0);
 	if (flags < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"can't get flags for connfd %d\n", fd);
 		return -2;
 	}
 	if ((flags & O_NONBLOCK) && fcntl(fd, F_SETFL, flags & ~O_NONBLOCK)) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"can't disable nonblocking on fd %d\n", fd);
 		return -2;
 	}
@@ -460,7 +460,7 @@  vhost_user_client_reconnect(void *arg __rte_unused)
 						sizeof(reconn->un));
 			if (ret == -2) {
 				close(reconn->fd);
-				RTE_LOG(ERR, VHOST_CONFIG,
+				VHOST_LOG_CONFIG(ERR,
 					"reconnection for fd %d failed\n",
 					reconn->fd);
 				goto remove_fd;
@@ -468,7 +468,7 @@  vhost_user_client_reconnect(void *arg __rte_unused)
 			if (ret == -1)
 				continue;
 
-			RTE_LOG(INFO, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(INFO,
 				"%s: connected\n", reconn->vsocket->path);
 			vhost_user_add_connection(reconn->fd, reconn->vsocket);
 remove_fd:
@@ -490,7 +490,7 @@  vhost_user_reconnect_init(void)
 
 	ret = pthread_mutex_init(&reconn_list.mutex, NULL);
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG, "failed to initialize mutex");
+		VHOST_LOG_CONFIG(ERR, "failed to initialize mutex");
 		return ret;
 	}
 	TAILQ_INIT(&reconn_list.head);
@@ -498,9 +498,9 @@  vhost_user_reconnect_init(void)
 	ret = rte_ctrl_thread_create(&reconn_tid, "vhost_reconn", NULL,
 			     vhost_user_client_reconnect, NULL);
 	if (ret != 0) {
-		RTE_LOG(ERR, VHOST_CONFIG, "failed to create reconnect thread");
+		VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread");
 		if (pthread_mutex_destroy(&reconn_list.mutex)) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"failed to destroy reconnect mutex");
 		}
 	}
@@ -523,7 +523,7 @@  vhost_user_start_client(struct vhost_user_socket *vsocket)
 		return 0;
 	}
 
-	RTE_LOG(WARNING, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(WARNING,
 		"failed to connect to %s: %s\n",
 		path, strerror(errno));
 
@@ -532,10 +532,10 @@  vhost_user_start_client(struct vhost_user_socket *vsocket)
 		return -1;
 	}
 
-	RTE_LOG(INFO, VHOST_CONFIG, "%s: reconnecting...\n", path);
+	VHOST_LOG_CONFIG(INFO, "%s: reconnecting...\n", path);
 	reconn = malloc(sizeof(*reconn));
 	if (reconn == NULL) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"failed to allocate memory for reconnect\n");
 		close(fd);
 		return -1;
@@ -690,7 +690,7 @@  rte_vhost_driver_get_features(const char *path, uint64_t *features)
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 	if (!vsocket) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"socket file %s is not registered yet.\n", path);
 		ret = -1;
 		goto unlock_exit;
@@ -704,7 +704,7 @@  rte_vhost_driver_get_features(const char *path, uint64_t *features)
 	}
 
 	if (vdpa_dev->ops->get_features(did, &vdpa_features) < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"failed to get vdpa features "
 				"for socket file %s.\n", path);
 		ret = -1;
@@ -745,7 +745,7 @@  rte_vhost_driver_get_protocol_features(const char *path,
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 	if (!vsocket) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"socket file %s is not registered yet.\n", path);
 		ret = -1;
 		goto unlock_exit;
@@ -760,7 +760,7 @@  rte_vhost_driver_get_protocol_features(const char *path,
 
 	if (vdpa_dev->ops->get_protocol_features(did,
 				&vdpa_protocol_features) < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"failed to get vdpa protocol features "
 				"for socket file %s.\n", path);
 		ret = -1;
@@ -787,7 +787,7 @@  rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num)
 	pthread_mutex_lock(&vhost_user.mutex);
 	vsocket = find_vhost_user_socket(path);
 	if (!vsocket) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"socket file %s is not registered yet.\n", path);
 		ret = -1;
 		goto unlock_exit;
@@ -801,7 +801,7 @@  rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num)
 	}
 
 	if (vdpa_dev->ops->get_queue_num(did, &vdpa_queue_num) < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"failed to get vdpa queue number "
 				"for socket file %s.\n", path);
 		ret = -1;
@@ -846,7 +846,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 	pthread_mutex_lock(&vhost_user.mutex);
 
 	if (vhost_user.vsocket_cnt == MAX_VHOST_SOCKET) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"error: the number of vhost sockets reaches maximum\n");
 		goto out;
 	}
@@ -857,7 +857,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 	memset(vsocket, 0, sizeof(struct vhost_user_socket));
 	vsocket->path = strdup(path);
 	if (vsocket->path == NULL) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"error: failed to copy socket path string\n");
 		vhost_user_socket_mem_free(vsocket);
 		goto out;
@@ -865,7 +865,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 	TAILQ_INIT(&vsocket->conn_list);
 	ret = pthread_mutex_init(&vsocket->conn_mutex, NULL);
 	if (ret) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"error: failed to init connection mutex\n");
 		goto out_free;
 	}
@@ -897,7 +897,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 		vsocket->supported_features &= ~(1ULL << VIRTIO_F_IN_ORDER);
 		vsocket->features &= ~(1ULL << VIRTIO_F_IN_ORDER);
 
-		RTE_LOG(INFO, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(INFO,
 			"Dequeue zero copy requested, disabling postcopy support\n");
 		vsocket->protocol_features &=
 			~(1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT);
@@ -913,7 +913,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 			~(1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT);
 	} else {
 #ifndef RTE_LIBRTE_VHOST_POSTCOPY
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Postcopy requested but not compiled\n");
 		ret = -1;
 		goto out_mutex;
@@ -941,7 +941,7 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 
 out_mutex:
 	if (pthread_mutex_destroy(&vsocket->conn_mutex)) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"error: failed to destroy connection mutex\n");
 	}
 out_free:
@@ -1015,7 +1015,7 @@  rte_vhost_driver_unregister(const char *path)
 					goto again;
 				}
 
-				RTE_LOG(INFO, VHOST_CONFIG,
+				VHOST_LOG_CONFIG(INFO,
 					"free connfd = %d for device '%s'\n",
 					conn->connfd, path);
 				close(conn->connfd);
@@ -1099,7 +1099,7 @@  rte_vhost_driver_start(const char *path)
 		 * rebuild the wait list of poll.
 		 */
 		if (fdset_pipe_init(&vhost_user.fdset) < 0) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"failed to create pipe for vhost fdset\n");
 			return -1;
 		}
@@ -1108,7 +1108,7 @@  rte_vhost_driver_start(const char *path)
 			"vhost-events", NULL, fdset_event_dispatch,
 			&vhost_user.fdset);
 		if (ret != 0) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"failed to create fdset handling thread");
 
 			fdset_pipe_uninit(&vhost_user.fdset);
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 981837b5d..0cc5edf0a 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -27,6 +27,9 @@ 
 
 struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
 
+int vhost_config_log_level;
+int vhost_data_log_level;
+
 /* Called with iotlb_lock read-locked */
 uint64_t
 __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
@@ -57,7 +60,7 @@  __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 		vhost_user_iotlb_pending_insert(vq, iova, perm);
 		if (vhost_user_iotlb_miss(dev, iova, perm)) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"IOTLB miss req failed for IOVA 0x%" PRIx64 "\n",
 				iova);
 			vhost_user_iotlb_pending_remove(vq, iova, 1, perm);
@@ -394,7 +397,7 @@  init_vring_queue(struct virtio_net *dev, uint32_t vring_idx)
 	struct vhost_virtqueue *vq;
 
 	if (vring_idx >= VHOST_MAX_VRING) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"Failed not init vring, out of bound (%d)\n",
 				vring_idx);
 		return;
@@ -421,7 +424,7 @@  reset_vring_queue(struct virtio_net *dev, uint32_t vring_idx)
 	int callfd;
 
 	if (vring_idx >= VHOST_MAX_VRING) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"Failed not init vring, out of bound (%d)\n",
 				vring_idx);
 		return;
@@ -440,7 +443,7 @@  alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx)
 
 	vq = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0);
 	if (vq == NULL) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Failed to allocate memory for vring:%u.\n", vring_idx);
 		return -1;
 	}
@@ -491,14 +494,14 @@  vhost_new_device(void)
 	}
 
 	if (i == MAX_VHOST_DEVICE) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Failed to find a free slot for new device.\n");
 		return -1;
 	}
 
 	dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
 	if (dev == NULL) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Failed to allocate memory for new dev.\n");
 		return -1;
 	}
@@ -639,7 +642,7 @@  rte_vhost_get_numa_node(int vid)
 	ret = get_mempolicy(&numa_node, NULL, 0, dev,
 			    MPOL_F_NODE | MPOL_F_ADDR);
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"(%d) failed to query numa node: %s\n",
 			vid, rte_strerror(errno));
 		return -1;
@@ -897,7 +900,7 @@  rte_vhost_rx_queue_count(int vid, uint16_t qid)
 		return 0;
 
 	if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) {
-		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+		VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, qid);
 		return 0;
 	}
@@ -976,3 +979,14 @@  int rte_vhost_extern_callback_register(int vid,
 	dev->extern_data = ctx;
 	return 0;
 }
+
+RTE_INIT(vhost_log_init)
+{
+	vhost_config_log_level = rte_log_register("lib.vhost.config");
+	if (vhost_config_log_level >= 0)
+		rte_log_set_level(vhost_config_log_level, RTE_LOG_INFO);
+
+	vhost_data_log_level = rte_log_register("lib.vhost.data");
+	if (vhost_data_log_level >= 0)
+		rte_log_set_level(vhost_data_log_level, RTE_LOG_WARNING);
+}
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 884befa85..13449aafc 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -393,14 +393,21 @@  vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	vhost_log_write(dev, vq->log_guest_addr + offset, len);
 }
 
-/* Macros for printing using RTE_LOG */
-#define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
-#define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER1
+extern int vhost_config_log_level;
+extern int vhost_data_log_level;
+
+#define VHOST_LOG_CONFIG(level, fmt, args...)			\
+	rte_log(RTE_LOG_ ## level, vhost_config_log_level,	\
+		"VHOST_CONFIG: " fmt, ##args)
+
+#define VHOST_LOG_DATA(level, fmt, args...) \
+	(void)((RTE_LOG_ ## level <= RTE_LOG_DP_LEVEL) ?	\
+	 rte_log(RTE_LOG_ ## level,  vhost_data_log_level,	\
+		"VHOST_DATA : " fmt, ##args) :			\
+	 0)
 
 #ifdef RTE_LIBRTE_VHOST_DEBUG
 #define VHOST_MAX_PRINT_BUFF 6072
-#define VHOST_LOG_DEBUG(log_type, fmt, args...) \
-	RTE_LOG(DEBUG, log_type, fmt, ##args)
 #define PRINT_PACKET(device, addr, size, header) do { \
 	char *pkt_addr = (char *)(addr); \
 	unsigned int index; \
@@ -416,10 +423,9 @@  vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	} \
 	snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
 	\
-	VHOST_LOG_DEBUG(VHOST_DATA, "%s", packet); \
+	VHOST_LOG_DATA(DEBUG, "%s", packet); \
 } while (0)
 #else
-#define VHOST_LOG_DEBUG(log_type, fmt, args...) do {} while (0)
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
 #endif
 
@@ -453,7 +459,7 @@  get_device(int vid)
 	struct virtio_net *dev = vhost_devices[vid];
 
 	if (unlikely(!dev)) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"(%d) device not found.\n", vid);
 	}
 
@@ -536,7 +542,7 @@  vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 		vq->signalled_used = new;
 		vq->signalled_used_valid = true;
 
-		VHOST_LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
+		VHOST_LOG_DATA(DEBUG, "%s: used_event_idx=%d, old=%d, new=%d\n",
 			__func__,
 			vhost_used_event(vq),
 			old, new);
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 0b72648a5..2dd79b46e 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -251,7 +251,7 @@  vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg,
 
 	rte_vhost_driver_get_features(dev->ifname, &vhost_features);
 	if (features & ~vhost_features) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"(%d) received invalid negotiated features.\n",
 			dev->vid);
 		return RTE_VHOST_MSG_RESULT_ERR;
@@ -267,7 +267,7 @@  vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg,
 		 * is enabled when the live-migration starts.
 		 */
 		if ((dev->features ^ features) & ~(1ULL << VHOST_F_LOG_ALL)) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"(%d) features changed while device is running.\n",
 				dev->vid);
 			return RTE_VHOST_MSG_RESULT_ERR;
@@ -284,9 +284,9 @@  vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	} else {
 		dev->vhost_hlen = sizeof(struct virtio_net_hdr);
 	}
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"negotiated Virtio features: 0x%" PRIx64 "\n", dev->features);
-	VHOST_LOG_DEBUG(VHOST_CONFIG,
+	VHOST_LOG_CONFIG(DEBUG,
 		"(%d) mergeable RX buffers %s, virtio 1 %s\n",
 		dev->vid,
 		(dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF)) ? "on" : "off",
@@ -339,7 +339,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 	 *   value is 32768.
 	 */
 	if ((vq->size & (vq->size - 1)) || vq->size > 32768) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"invalid virtqueue size %u\n", vq->size);
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
@@ -351,7 +351,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 		vq->zmbufs = rte_zmalloc(NULL, vq->zmbuf_size *
 					 sizeof(struct zcopy_mbuf), 0);
 		if (vq->zmbufs == NULL) {
-			RTE_LOG(WARNING, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(WARNING,
 				"failed to allocate mem for zero copy; "
 				"zero copy is force disabled\n");
 			dev->dequeue_zero_copy = 0;
@@ -365,7 +365,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 				sizeof(struct vring_used_elem_packed),
 				RTE_CACHE_LINE_SIZE);
 		if (!vq->shadow_used_packed) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 					"failed to allocate memory for shadow used ring.\n");
 			return RTE_VHOST_MSG_RESULT_ERR;
 		}
@@ -375,7 +375,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 				vq->size * sizeof(struct vring_used_elem),
 				RTE_CACHE_LINE_SIZE);
 		if (!vq->shadow_used_split) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 					"failed to allocate memory for shadow used ring.\n");
 			return RTE_VHOST_MSG_RESULT_ERR;
 		}
@@ -385,7 +385,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 				vq->size * sizeof(struct batch_copy_elem),
 				RTE_CACHE_LINE_SIZE);
 	if (!vq->batch_copy_elems) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"failed to allocate memory for batching copy.\n");
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
@@ -420,12 +420,12 @@  numa_realloc(struct virtio_net *dev, int index)
 	ret |= get_mempolicy(&oldnode, NULL, 0, old_vq,
 			     MPOL_F_NODE | MPOL_F_ADDR);
 	if (ret) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Unable to get vq numa information.\n");
 		return dev;
 	}
 	if (oldnode != newnode) {
-		RTE_LOG(INFO, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(INFO,
 			"reallocate vq from %d to %d node\n", oldnode, newnode);
 		vq = rte_malloc_socket(NULL, sizeof(*vq), 0, newnode);
 		if (!vq)
@@ -481,12 +481,12 @@  numa_realloc(struct virtio_net *dev, int index)
 	ret = get_mempolicy(&oldnode, NULL, 0, old_dev,
 			    MPOL_F_NODE | MPOL_F_ADDR);
 	if (ret) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Unable to get dev numa information.\n");
 		goto out;
 	}
 	if (oldnode != newnode) {
-		RTE_LOG(INFO, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(INFO,
 			"reallocate dev from %d to %d node\n",
 			oldnode, newnode);
 		dev = rte_malloc_socket(NULL, sizeof(*dev), 0, newnode);
@@ -585,7 +585,7 @@  translate_ring_addresses(struct virtio_net *dev, int vq_index)
 		if (vq->desc_packed == NULL ||
 				len != sizeof(struct vring_packed_desc) *
 				vq->size) {
-			RTE_LOG(DEBUG, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(DEBUG,
 				"(%d) failed to map desc_packed ring.\n",
 				dev->vid);
 			return dev;
@@ -601,7 +601,7 @@  translate_ring_addresses(struct virtio_net *dev, int vq_index)
 					vq, addr->avail_user_addr, &len);
 		if (vq->driver_event == NULL ||
 				len != sizeof(struct vring_packed_desc_event)) {
-			RTE_LOG(DEBUG, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(DEBUG,
 				"(%d) failed to find driver area address.\n",
 				dev->vid);
 			return dev;
@@ -613,7 +613,7 @@  translate_ring_addresses(struct virtio_net *dev, int vq_index)
 					vq, addr->used_user_addr, &len);
 		if (vq->device_event == NULL ||
 				len != sizeof(struct vring_packed_desc_event)) {
-			RTE_LOG(DEBUG, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(DEBUG,
 				"(%d) failed to find device area address.\n",
 				dev->vid);
 			return dev;
@@ -630,7 +630,7 @@  translate_ring_addresses(struct virtio_net *dev, int vq_index)
 	vq->desc = (struct vring_desc *)(uintptr_t)ring_addr_to_vva(dev,
 			vq, addr->desc_user_addr, &len);
 	if (vq->desc == 0 || len != sizeof(struct vring_desc) * vq->size) {
-		RTE_LOG(DEBUG, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(DEBUG,
 			"(%d) failed to map desc ring.\n",
 			dev->vid);
 		return dev;
@@ -647,7 +647,7 @@  translate_ring_addresses(struct virtio_net *dev, int vq_index)
 	vq->avail = (struct vring_avail *)(uintptr_t)ring_addr_to_vva(dev,
 			vq, addr->avail_user_addr, &len);
 	if (vq->avail == 0 || len != expected_len) {
-		RTE_LOG(DEBUG, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(DEBUG,
 			"(%d) failed to map avail ring.\n",
 			dev->vid);
 		return dev;
@@ -661,14 +661,14 @@  translate_ring_addresses(struct virtio_net *dev, int vq_index)
 	vq->used = (struct vring_used *)(uintptr_t)ring_addr_to_vva(dev,
 			vq, addr->used_user_addr, &len);
 	if (vq->used == 0 || len != expected_len) {
-		RTE_LOG(DEBUG, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(DEBUG,
 			"(%d) failed to map used ring.\n",
 			dev->vid);
 		return dev;
 	}
 
 	if (vq->last_used_idx != vq->used->idx) {
-		RTE_LOG(WARNING, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(WARNING,
 			"last_used_idx (%u) and vq->used->idx (%u) mismatches; "
 			"some packets maybe resent for Tx and dropped for Rx\n",
 			vq->last_used_idx, vq->used->idx);
@@ -678,13 +678,13 @@  translate_ring_addresses(struct virtio_net *dev, int vq_index)
 
 	vq->log_guest_addr = addr->log_guest_addr;
 
-	VHOST_LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
+	VHOST_LOG_CONFIG(DEBUG, "(%d) mapped address desc: %p\n",
 			dev->vid, vq->desc);
-	VHOST_LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address avail: %p\n",
+	VHOST_LOG_CONFIG(DEBUG, "(%d) mapped address avail: %p\n",
 			dev->vid, vq->avail);
-	VHOST_LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address used: %p\n",
+	VHOST_LOG_CONFIG(DEBUG, "(%d) mapped address used: %p\n",
 			dev->vid, vq->used);
-	VHOST_LOG_DEBUG(VHOST_CONFIG, "(%d) log_guest_addr: %" PRIx64 "\n",
+	VHOST_LOG_CONFIG(DEBUG, "(%d) log_guest_addr: %" PRIx64 "\n",
 			dev->vid, vq->log_guest_addr);
 
 	return dev;
@@ -775,7 +775,7 @@  add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr,
 		dev->guest_pages = realloc(dev->guest_pages,
 					dev->max_guest_pages * sizeof(*page));
 		if (!dev->guest_pages) {
-			RTE_LOG(ERR, VHOST_CONFIG, "cannot realloc guest_pages\n");
+			VHOST_LOG_CONFIG(ERR, "cannot realloc guest_pages\n");
 			free(old_pages);
 			return -1;
 		}
@@ -847,7 +847,7 @@  dump_guest_pages(struct virtio_net *dev)
 	for (i = 0; i < dev->nr_guest_pages; i++) {
 		page = &dev->guest_pages[i];
 
-		RTE_LOG(INFO, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(INFO,
 			"guest physical page region %u\n"
 			"\t guest_phys_addr: %" PRIx64 "\n"
 			"\t host_phys_addr : %" PRIx64 "\n"
@@ -902,13 +902,13 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	int fd;
 
 	if (memory->nregions > VHOST_MEMORY_MAX_NREGIONS) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"too many memory regions (%u)\n", memory->nregions);
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
 
 	if (dev->mem && !vhost_memory_changed(memory, dev->mem)) {
-		RTE_LOG(INFO, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(INFO,
 			"(%d) memory regions not changed\n", dev->vid);
 
 		for (i = 0; i < memory->nregions; i++)
@@ -934,7 +934,7 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 		dev->guest_pages = malloc(dev->max_guest_pages *
 						sizeof(struct guest_page));
 		if (dev->guest_pages == NULL) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"(%d) failed to allocate memory "
 				"for dev->guest_pages\n",
 				dev->vid);
@@ -945,7 +945,7 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	dev->mem = rte_zmalloc("vhost-mem-table", sizeof(struct rte_vhost_memory) +
 		sizeof(struct rte_vhost_mem_region) * memory->nregions, 0);
 	if (dev->mem == NULL) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"(%d) failed to allocate memory for dev->mem\n",
 			dev->vid);
 		return RTE_VHOST_MSG_RESULT_ERR;
@@ -965,7 +965,7 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 
 		/* Check for memory_size + mmap_offset overflow */
 		if (mmap_offset >= -reg->size) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"mmap_offset (%#"PRIx64") and memory_size "
 				"(%#"PRIx64") overflow\n",
 				mmap_offset, reg->size);
@@ -984,7 +984,7 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 		 */
 		alignment = get_blk_size(fd);
 		if (alignment == (uint64_t)-1) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"couldn't get hugepage size through fstat\n");
 			goto err_mmap;
 		}
@@ -995,7 +995,7 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 				 MAP_SHARED | populate, fd, 0);
 
 		if (mmap_addr == MAP_FAILED) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"mmap region %u failed.\n", i);
 			goto err_mmap;
 		}
@@ -1007,13 +1007,13 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 
 		if (dev->dequeue_zero_copy)
 			if (add_guest_pages(dev, reg, alignment) < 0) {
-				RTE_LOG(ERR, VHOST_CONFIG,
+				VHOST_LOG_CONFIG(ERR,
 					"adding guest pages to region %u failed.\n",
 					i);
 				goto err_mmap;
 			}
 
-		RTE_LOG(INFO, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(INFO,
 			"guest memory region %u, size: 0x%" PRIx64 "\n"
 			"\t guest physical addr: 0x%" PRIx64 "\n"
 			"\t guest virtual  addr: 0x%" PRIx64 "\n"
@@ -1051,12 +1051,12 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 		 */
 		VhostUserMsg ack_msg;
 		if (read_vhost_message(main_fd, &ack_msg) <= 0) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"Failed to read qemu ack on postcopy set-mem-table\n");
 			goto err_mmap;
 		}
 		if (ack_msg.request.master != VHOST_USER_SET_MEM_TABLE) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"Bad qemu ack on postcopy set-mem-table (%d)\n",
 				ack_msg.request.master);
 			goto err_mmap;
@@ -1079,13 +1079,13 @@  vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg,
 
 			if (ioctl(dev->postcopy_ufd, UFFDIO_REGISTER,
 						&reg_struct)) {
-				RTE_LOG(ERR, VHOST_CONFIG,
+				VHOST_LOG_CONFIG(ERR,
 					"Failed to register ufd for region %d: (ufd = %d) %s\n",
 					i, dev->postcopy_ufd,
 					strerror(errno));
 				goto err_mmap;
 			}
-			RTE_LOG(INFO, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(INFO,
 				"\t userfaultfd registered for range : %llx - %llx\n",
 				reg_struct.range.start,
 				reg_struct.range.start +
@@ -1162,7 +1162,7 @@  virtio_is_ready(struct virtio_net *dev)
 			return 0;
 	}
 
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"virtio is now ready for processing.\n");
 	return 1;
 }
@@ -1180,7 +1180,7 @@  vhost_user_set_vring_call(struct virtio_net **pdev, struct VhostUserMsg *msg,
 		file.fd = VIRTIO_INVALID_EVENTFD;
 	else
 		file.fd = msg->fds[0];
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"vring call idx:%d file:%d\n", file.index, file.fd);
 
 	vq = dev->virtqueue[file.index];
@@ -1198,7 +1198,7 @@  static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused,
 {
 	if (!(msg->payload.u64 & VHOST_USER_VRING_NOFD_MASK))
 		close(msg->fds[0]);
-	RTE_LOG(INFO, VHOST_CONFIG, "not implemented\n");
+	VHOST_LOG_CONFIG(INFO, "not implemented\n");
 
 	return RTE_VHOST_MSG_RESULT_OK;
 }
@@ -1216,7 +1216,7 @@  vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *msg,
 		file.fd = VIRTIO_INVALID_EVENTFD;
 	else
 		file.fd = msg->fds[0];
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
 
 	/* Interpret ring addresses only when ring is started. */
@@ -1286,7 +1286,7 @@  vhost_user_get_vring_base(struct virtio_net **pdev,
 		msg->payload.state.num = vq->last_avail_idx;
 	}
 
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"vring base idx:%d file:%d\n", msg->payload.state.index,
 		msg->payload.state.num);
 	/*
@@ -1340,7 +1340,7 @@  vhost_user_set_vring_enable(struct virtio_net **pdev,
 	struct rte_vdpa_device *vdpa_dev;
 	int did = -1;
 
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"set queue enable: %d to qp idx: %d\n",
 		enable, index);
 
@@ -1401,14 +1401,14 @@  vhost_user_set_protocol_features(struct virtio_net **pdev,
 	rte_vhost_driver_get_protocol_features(dev->ifname,
 			&slave_protocol_features);
 	if (protocol_features & ~slave_protocol_features) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"(%d) received invalid protocol features.\n",
 			dev->vid);
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
 
 	dev->protocol_features = protocol_features;
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"negotiated Vhost-user protocol features: 0x%" PRIx64 "\n",
 		dev->protocol_features);
 
@@ -1425,12 +1425,12 @@  vhost_user_set_log_base(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	void *addr;
 
 	if (fd < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG, "invalid log fd: %d\n", fd);
+		VHOST_LOG_CONFIG(ERR, "invalid log fd: %d\n", fd);
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
 
 	if (msg->size != sizeof(VhostUserLog)) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"invalid log base msg size: %"PRId32" != %d\n",
 			msg->size, (int)sizeof(VhostUserLog));
 		return RTE_VHOST_MSG_RESULT_ERR;
@@ -1441,13 +1441,13 @@  vhost_user_set_log_base(struct virtio_net **pdev, struct VhostUserMsg *msg,
 
 	/* Don't allow mmap_offset to point outside the mmap region */
 	if (off > size) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"log offset %#"PRIx64" exceeds log size %#"PRIx64"\n",
 			off, size);
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
 
-	RTE_LOG(INFO, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(INFO,
 		"log mmap size: %"PRId64", offset: %"PRId64"\n",
 		size, off);
 
@@ -1458,7 +1458,7 @@  vhost_user_set_log_base(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	addr = mmap(0, size + off, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	close(fd);
 	if (addr == MAP_FAILED) {
-		RTE_LOG(ERR, VHOST_CONFIG, "mmap log base failed!\n");
+		VHOST_LOG_CONFIG(ERR, "mmap log base failed!\n");
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
 
@@ -1488,7 +1488,7 @@  static int vhost_user_set_log_fd(struct virtio_net **pdev __rte_unused,
 			int main_fd __rte_unused)
 {
 	close(msg->fds[0]);
-	RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n");
+	VHOST_LOG_CONFIG(INFO, "not implemented.\n");
 
 	return RTE_VHOST_MSG_RESULT_OK;
 }
@@ -1510,7 +1510,7 @@  vhost_user_send_rarp(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	struct rte_vdpa_device *vdpa_dev;
 	int did = -1;
 
-	RTE_LOG(DEBUG, VHOST_CONFIG,
+	VHOST_LOG_CONFIG(DEBUG,
 		":: mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
 		mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
 	memcpy(dev->mac.addr_bytes, mac, 6);
@@ -1539,7 +1539,7 @@  vhost_user_net_set_mtu(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	struct virtio_net *dev = *pdev;
 	if (msg->payload.u64 < VIRTIO_MIN_MTU ||
 			msg->payload.u64 > VIRTIO_MAX_MTU) {
-		RTE_LOG(ERR, VHOST_CONFIG, "Invalid MTU size (%"PRIu64")\n",
+		VHOST_LOG_CONFIG(ERR, "Invalid MTU size (%"PRIu64")\n",
 				msg->payload.u64);
 
 		return RTE_VHOST_MSG_RESULT_ERR;
@@ -1558,7 +1558,7 @@  vhost_user_set_req_fd(struct virtio_net **pdev, struct VhostUserMsg *msg,
 	int fd = msg->fds[0];
 
 	if (fd < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"Invalid file descriptor for slave channel (%d)\n",
 				fd);
 		return RTE_VHOST_MSG_RESULT_ERR;
@@ -1656,7 +1656,7 @@  vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg,
 		}
 		break;
 	default:
-		RTE_LOG(ERR, VHOST_CONFIG, "Invalid IOTLB message type (%d)\n",
+		VHOST_LOG_CONFIG(ERR, "Invalid IOTLB message type (%d)\n",
 				imsg->type);
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
@@ -1676,14 +1676,14 @@  vhost_user_set_postcopy_advise(struct virtio_net **pdev,
 	dev->postcopy_ufd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
 
 	if (dev->postcopy_ufd == -1) {
-		RTE_LOG(ERR, VHOST_CONFIG, "Userfaultfd not available: %s\n",
+		VHOST_LOG_CONFIG(ERR, "Userfaultfd not available: %s\n",
 			strerror(errno));
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
 	api_struct.api = UFFD_API;
 	api_struct.features = 0;
 	if (ioctl(dev->postcopy_ufd, UFFDIO_API, &api_struct)) {
-		RTE_LOG(ERR, VHOST_CONFIG, "UFFDIO_API ioctl failure: %s\n",
+		VHOST_LOG_CONFIG(ERR, "UFFDIO_API ioctl failure: %s\n",
 			strerror(errno));
 		close(dev->postcopy_ufd);
 		dev->postcopy_ufd = -1;
@@ -1709,7 +1709,7 @@  vhost_user_set_postcopy_listen(struct virtio_net **pdev,
 	struct virtio_net *dev = *pdev;
 
 	if (dev->mem && dev->mem->nregions) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Regions already registered at postcopy-listen\n");
 		return RTE_VHOST_MSG_RESULT_ERR;
 	}
@@ -1783,7 +1783,7 @@  read_vhost_message(int sockfd, struct VhostUserMsg *msg)
 
 	if (msg->size) {
 		if (msg->size > sizeof(msg->payload)) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"invalid msg size: %d\n", msg->size);
 			return -1;
 		}
@@ -1791,7 +1791,7 @@  read_vhost_message(int sockfd, struct VhostUserMsg *msg)
 		if (ret <= 0)
 			return ret;
 		if (ret != (int)msg->size) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"read control message failed\n");
 			return -1;
 		}
@@ -1867,7 +1867,7 @@  vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev,
 	}
 
 	if (vring_idx >= VHOST_MAX_VRING) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"invalid vring index: %u\n", vring_idx);
 		return -1;
 	}
@@ -1931,7 +1931,7 @@  vhost_user_msg_handler(int vid, int fd)
 	if (!dev->notify_ops) {
 		dev->notify_ops = vhost_driver_callback_get(dev->ifname);
 		if (!dev->notify_ops) {
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"failed to get callback ops for driver %s\n",
 				dev->ifname);
 			return -1;
@@ -1941,10 +1941,10 @@  vhost_user_msg_handler(int vid, int fd)
 	ret = read_vhost_message(fd, &msg);
 	if (ret <= 0) {
 		if (ret < 0)
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"vhost read message failed\n");
 		else
-			RTE_LOG(INFO, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(INFO,
 				"vhost peer closed\n");
 
 		return -1;
@@ -1955,18 +1955,18 @@  vhost_user_msg_handler(int vid, int fd)
 	if (request > VHOST_USER_NONE && request < VHOST_USER_MAX &&
 			vhost_message_str[request]) {
 		if (request != VHOST_USER_IOTLB_MSG)
-			RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n",
+			VHOST_LOG_CONFIG(INFO, "read message %s\n",
 				vhost_message_str[request]);
 		else
-			RTE_LOG(DEBUG, VHOST_CONFIG, "read message %s\n",
+			VHOST_LOG_CONFIG(DEBUG, "read message %s\n",
 				vhost_message_str[request]);
 	} else {
-		RTE_LOG(DEBUG, VHOST_CONFIG, "External request %d\n", request);
+		VHOST_LOG_CONFIG(DEBUG, "External request %d\n", request);
 	}
 
 	ret = vhost_user_check_and_alloc_queue_pair(dev, &msg);
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"failed to alloc queue\n");
 		return -1;
 	}
@@ -2028,19 +2028,19 @@  vhost_user_msg_handler(int vid, int fd)
 
 		switch (ret) {
 		case RTE_VHOST_MSG_RESULT_ERR:
-			RTE_LOG(ERR, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(ERR,
 				"Processing %s failed.\n",
 				vhost_message_str[request]);
 			handled = true;
 			break;
 		case RTE_VHOST_MSG_RESULT_OK:
-			RTE_LOG(DEBUG, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(DEBUG,
 				"Processing %s succeeded.\n",
 				vhost_message_str[request]);
 			handled = true;
 			break;
 		case RTE_VHOST_MSG_RESULT_REPLY:
-			RTE_LOG(DEBUG, VHOST_CONFIG,
+			VHOST_LOG_CONFIG(DEBUG,
 				"Processing %s succeeded and needs reply.\n",
 				vhost_message_str[request]);
 			send_vhost_reply(fd, &msg);
@@ -2074,7 +2074,7 @@  vhost_user_msg_handler(int vid, int fd)
 
 	/* If message was not handled at this stage, treat it as an error */
 	if (!handled) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"vhost message (req: %d) was not handled.\n", request);
 		ret = RTE_VHOST_MSG_RESULT_ERR;
 	}
@@ -2090,7 +2090,7 @@  vhost_user_msg_handler(int vid, int fd)
 		msg.fd_num = 0;
 		send_vhost_reply(fd, &msg);
 	} else if (ret == RTE_VHOST_MSG_RESULT_ERR) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"vhost message handling failed.\n");
 		return -1;
 	}
@@ -2100,7 +2100,7 @@  vhost_user_msg_handler(int vid, int fd)
 
 		if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
 			if (dev->dequeue_zero_copy) {
-				RTE_LOG(INFO, VHOST_CONFIG,
+				VHOST_LOG_CONFIG(INFO,
 						"dequeue zero copy is enabled\n");
 			}
 
@@ -2137,7 +2137,7 @@  static int process_slave_message_reply(struct virtio_net *dev,
 	}
 
 	if (msg_reply.request.slave != msg->request.slave) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Received unexpected msg type (%u), expected %u\n",
 			msg_reply.request.slave, msg->request.slave);
 		ret = -1;
@@ -2168,7 +2168,7 @@  vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm)
 
 	ret = send_vhost_message(dev->slave_req_fd, &msg);
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 				"Failed to send IOTLB miss message (%d)\n",
 				ret);
 		return ret;
@@ -2203,7 +2203,7 @@  static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev,
 
 	ret = send_vhost_slave_message(dev, &msg);
 	if (ret < 0) {
-		RTE_LOG(ERR, VHOST_CONFIG,
+		VHOST_LOG_CONFIG(ERR,
 			"Failed to set host notifier (%d)\n", ret);
 		return ret;
 	}
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 5b85b832d..756ee9aa8 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -680,7 +680,7 @@  copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	else
 		hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)hdr_addr;
 
-	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) RX: num merge buffers %d\n",
+	VHOST_LOG_DATA(DEBUG, "(%d) RX: num merge buffers %d\n",
 		dev->vid, num_buffers);
 
 	if (unlikely(buf_len < dev->vhost_hlen)) {
@@ -800,14 +800,14 @@  virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (unlikely(reserve_avail_buf_split(dev, vq,
 						pkt_len, buf_vec, &num_buffers,
 						avail_head, &nr_vec) < 0)) {
-			VHOST_LOG_DEBUG(VHOST_DATA,
+			VHOST_LOG_DATA(DEBUG,
 				"(%d) failed to get enough desc from vring\n",
 				dev->vid);
 			vq->shadow_used_idx -= num_buffers;
 			break;
 		}
 
-		VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
+		VHOST_LOG_DATA(DEBUG, "(%d) current index %d | end index %d\n",
 			dev->vid, vq->last_avail_idx,
 			vq->last_avail_idx + num_buffers);
 
@@ -847,14 +847,14 @@  virtio_dev_rx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (unlikely(reserve_avail_buf_packed(dev, vq,
 						pkt_len, buf_vec, &nr_vec,
 						&num_buffers, &nr_descs) < 0)) {
-			VHOST_LOG_DEBUG(VHOST_DATA,
+			VHOST_LOG_DATA(DEBUG,
 				"(%d) failed to get enough desc from vring\n",
 				dev->vid);
 			vq->shadow_used_idx -= num_buffers;
 			break;
 		}
 
-		VHOST_LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
+		VHOST_LOG_DATA(DEBUG, "(%d) current index %d | end index %d\n",
 			dev->vid, vq->last_avail_idx,
 			vq->last_avail_idx + num_buffers);
 
@@ -889,9 +889,9 @@  virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 	struct vhost_virtqueue *vq;
 	uint32_t nb_tx = 0;
 
-	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
+	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {
-		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+		VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, queue_id);
 		return 0;
 	}
@@ -939,7 +939,7 @@  rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
 		return 0;
 
 	if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
-		RTE_LOG(ERR, VHOST_DATA,
+		VHOST_LOG_DATA(ERR,
 			"(%d) %s: built-in vhost net backend is disabled.\n",
 			dev->vid, __func__);
 		return 0;
@@ -1056,7 +1056,7 @@  vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
 			m->l4_len = sizeof(struct rte_udp_hdr);
 			break;
 		default:
-			RTE_LOG(WARNING, VHOST_DATA,
+			VHOST_LOG_DATA(WARNING,
 				"unsupported gso type %u.\n", hdr->gso_type);
 			break;
 		}
@@ -1228,7 +1228,7 @@  copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		if (mbuf_avail == 0) {
 			cur = rte_pktmbuf_alloc(mbuf_pool);
 			if (unlikely(cur == NULL)) {
-				RTE_LOG(ERR, VHOST_DATA, "Failed to "
+				VHOST_LOG_DATA(ERR, "Failed to "
 					"allocate memory for mbuf.\n");
 				error = -1;
 				goto out;
@@ -1333,11 +1333,11 @@  virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 	rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);
 
-	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
+	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
 
 	count = RTE_MIN(count, MAX_PKT_BURST);
 	count = RTE_MIN(count, free_entries);
-	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
+	VHOST_LOG_DATA(DEBUG, "(%d) about to dequeue %u buffers\n",
 			dev->vid, count);
 
 	for (i = 0; i < count; i++) {
@@ -1359,7 +1359,7 @@  virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 		pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
 		if (unlikely(pkts[i] == NULL)) {
-			RTE_LOG(ERR, VHOST_DATA,
+			VHOST_LOG_DATA(ERR,
 				"Failed to allocate memory for mbuf.\n");
 			break;
 		}
@@ -1442,10 +1442,10 @@  virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 		}
 	}
 
-	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
+	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
 
 	count = RTE_MIN(count, MAX_PKT_BURST);
-	VHOST_LOG_DEBUG(VHOST_DATA, "(%d) about to dequeue %u buffers\n",
+	VHOST_LOG_DATA(DEBUG, "(%d) about to dequeue %u buffers\n",
 			dev->vid, count);
 
 	for (i = 0; i < count; i++) {
@@ -1468,7 +1468,7 @@  virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
 
 		pkts[i] = rte_pktmbuf_alloc(mbuf_pool);
 		if (unlikely(pkts[i] == NULL)) {
-			RTE_LOG(ERR, VHOST_DATA,
+			VHOST_LOG_DATA(ERR,
 				"Failed to allocate memory for mbuf.\n");
 			break;
 		}
@@ -1537,14 +1537,15 @@  rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 		return 0;
 
 	if (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {
-		RTE_LOG(ERR, VHOST_DATA,
+		VHOST_LOG_DATA(ERR,
 			"(%d) %s: built-in vhost net backend is disabled.\n",
 			dev->vid, __func__);
 		return 0;
 	}
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->nr_vring))) {
-		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+		VHOST_LOG_DATA(ERR,
+			"(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, queue_id);
 		return 0;
 	}
@@ -1589,8 +1590,7 @@  rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 
 		rarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac);
 		if (rarp_mbuf == NULL) {
-			RTE_LOG(ERR, VHOST_DATA,
-				"Failed to make RARP packet.\n");
+			VHOST_LOG_DATA(ERR, "Failed to make RARP packet.\n");
 			count = 0;
 			goto out;
 		}