![4c451585255c7245ecbd1a91a657287e.png](https://i-blog.csdnimg.cn/blog_migrate/1c1776d598bf8f1d9fe0e59381076f8c.jpeg)
背景
最近在分析ceph某个模块的时候,发现该模块没有日志输出模块(也就是无法直接使用dout打印日志),基于此整理了下怎么样可以正常使用日志打印。
实践
话不多说,直接贴代码好了。
定义子模块
如下,在subsys.h中添加想添加的子模块
root@fe4fcb2c09b7:/tmp/ceph-Luminous# git diff src/common/subsys.h
diff --git a/src/common/subsys.h b/src/common/subsys.h
index 6e6c26fa78..636451e180 100644
--- a/src/common/subsys.h
+++ b/src/common/subsys.h
@@ -77,3 +77,4 @@ SUBSYS(mgr, 1, 5)
SUBSYS(mgrc, 1, 5)
SUBSYS(dpdk, 1, 5)
SUBSYS(eventtrace, 1, 5)
+SUBSYS(aio, 1, 5) // 1和5代表默认的日志打印级别
使用
root@fe4fcb2c09b7:/tmp/ceph-Luminous#
root@fe4fcb2c09b7:/tmp/ceph-Luminous# git diff src/os/bluestore/aio.cc
diff --git a/src/os/bluestore/aio.cc b/src/os/bluestore/aio.cc
index 256f3db97f..21214f0e56 100644
--- a/src/os/bluestore/aio.cc
+++ b/src/os/bluestore/aio.cc
@@ -2,13 +2,30 @@
// vim: ts=8 sw=2 smarttab
+
+#include "common/debug.h"
+#include "common/errno.h"
+#include "include/assert.h"
+#include "common/ceph_context.h"
+ // 声明aio子模块
+#define dout_context g_ceph_context
+#define dout_subsys ceph_subsys_aio
+#undef dout_prefix
+#define dout_prefix *_dout << "aio "
int aio_queue_t::submit_batch(aio_iter begin, aio_iter end,
uint16_t aios_size, void *priv,
int *retries)
{
+ dout(3) << __func__ << "submit_batch" <<< dendl; // 可以使用dout打印了