]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common,crimson: add a seastar backend for logging
authorKefu Chai <kchai@redhat.com>
Tue, 28 Aug 2018 12:06:46 +0000 (20:06 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 6 Sep 2018 14:03:33 +0000 (22:03 +0800)
this logging backend serves as an intemediate solution before the LTTng
backend is ready. it maps
- -1 to error()
- 0  to warn()
- [1,5) to info()
- [5,10) to debug()
- [20,200] to trace()

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/dout.h
src/crimson/CMakeLists.txt
src/crimson/common/log.cc [new file with mode: 0644]
src/crimson/common/log.h [new file with mode: 0644]

index c423c0818b841134695bf178d6fbbe8a2ad9da2f..0ac365abe01cc3b4dd746cead9eddac39b3a915c 100644 (file)
 
 #include <type_traits>
 
+#include "include/assert.h"
+#ifdef WITH_SEASTAR
+#include <seastar/util/log.hh>
+#include "crimson/common/log.h"
+#include "crimson/common/config_proxy.h"
+#else
 #include "global/global_context.h"
 #include "common/ceph_context.h"
 #include "common/config.h"
 #include "common/likely.h"
 #include "common/Clock.h"
 #include "log/Log.h"
+#endif
 
 extern void dout_emergency(const char * const str);
 extern void dout_emergency(const std::string &str);
@@ -69,6 +76,31 @@ struct is_dynamic<dynamic_marker_t<T>> : public std::true_type {};
 // generic macros
 #define dout_prefix *_dout
 
+#ifdef WITH_SEASTAR
+#define dout_impl(cct, sub, v)                                          \
+  do {                                                                  \
+    if (ceph::common::local_conf()->subsys.should_gather(sub, v)) {     \
+      seastar::logger& _logger = ceph::get_logger(sub);                 \
+      const auto _lv = v;                                               \
+      std::ostringstream _out;                                          \
+      std::ostream* _dout = &_out;
+#define dendl_impl                              \
+     "";                                        \
+      const std::string _s = _out.str();        \
+      if (_lv < 0) {                            \
+        _logger.error(_s.c_str());              \
+      } else if (_lv < 1) {                     \
+        _logger.warn(_s.c_str());               \
+      } else if (_lv < 5) {                     \
+        _logger.info(_s.c_str());               \
+      } else if (_lv < 10) {                    \
+        _logger.debug(_s.c_str());              \
+      } else {                                  \
+        _logger.trace(_s.c_str());              \
+      }                                         \
+    }                                           \
+  } while (0)
+#else
 #define dout_impl(cct, sub, v)                                         \
   do {                                                                 \
   const bool should_gather = [&](const auto cctX) {                    \
@@ -93,6 +125,12 @@ struct is_dynamic<dynamic_marker_t<T>> : public std::true_type {};
     auto _dout_cct = cct;                                              \
     std::ostream* _dout = &_dout_e->get_ostream();
 
+#define dendl_impl std::flush;                         \
+    _dout_cct->_log->submit_entry(_dout_e);            \
+  }                                                    \
+  } while (0)
+#endif // WITH_SEASTAR
+
 #define lsubdout(cct, sub, v)  dout_impl(cct, ceph_subsys_##sub, v) dout_prefix
 #define ldout(cct, v)  dout_impl(cct, dout_subsys, v) dout_prefix
 #define lderr(cct) dout_impl(cct, ceph_subsys_, -1) dout_prefix
@@ -109,11 +147,6 @@ struct is_dynamic<dynamic_marker_t<T>> : public std::true_type {};
 #define ldlog_p1(cct, sub, lvl)                 \
   (cct->_conf->subsys.should_gather((sub), (lvl)))
 
-#define dendl_impl std::flush;                         \
-  _dout_cct->_log->submit_entry(_dout_e);              \
-    }                                          \
-  } while (0)
-
 #define dendl dendl_impl
 
 #endif
index d7b347ffcc6fffa4391e1a7e2271ab0f2213be64..020fea969ed50eb24d31104f4378ef8acec554b4 100644 (file)
@@ -7,7 +7,8 @@ set(crimson_thread_srcs
   thread/ThreadPool.cc
   thread/Throttle.cc)
 set(crimson_common_srcs
-  common/config_proxy.cc)
+  common/config_proxy.cc
+  common/log.cc)
 add_library(crimson STATIC
   ${crimson_common_srcs}
   ${crimson_net_srcs}
diff --git a/src/crimson/common/log.cc b/src/crimson/common/log.cc
new file mode 100644 (file)
index 0000000..6a57b23
--- /dev/null
@@ -0,0 +1,18 @@
+#include "log.h"
+
+static std::array<seastar::logger, ceph_subsys_get_num()> loggers{
+#define SUBSYS(name, log_level, gather_level) \
+  seastar::logger(#name),
+#define DEFAULT_SUBSYS(log_level, gather_level) \
+  seastar::logger("none"),
+  #include "common/subsys.h"
+#undef SUBSYS
+#undef DEFAULT_SUBSYS
+};
+
+namespace ceph {
+seastar::logger& get_logger(int subsys) {
+  assert(subsys < ceph_subsys_max);
+  return loggers[subsys];
+}
+}
diff --git a/src/crimson/common/log.h b/src/crimson/common/log.h
new file mode 100644 (file)
index 0000000..64ff336
--- /dev/null
@@ -0,0 +1,6 @@
+#include <seastar/util/log.hh>
+#include "common/subsys_types.h"
+
+namespace ceph {
+seastar::logger& get_logger(int subsys);
+}