From f59cb91264bca91a840c1aa84dba4c6165cbceaf Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 28 Aug 2018 20:06:46 +0800 Subject: [PATCH] common,crimson: add a seastar backend for logging 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 --- src/common/dout.h | 43 +++++++++++++++++++++++++++++++++----- src/crimson/CMakeLists.txt | 3 ++- src/crimson/common/log.cc | 18 ++++++++++++++++ src/crimson/common/log.h | 6 ++++++ 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/crimson/common/log.cc create mode 100644 src/crimson/common/log.h diff --git a/src/common/dout.h b/src/common/dout.h index c423c0818b841..0ac365abe01cc 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -18,12 +18,19 @@ #include +#include "include/assert.h" +#ifdef WITH_SEASTAR +#include +#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> : 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> : 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> : 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 diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index d7b347ffcc6ff..020fea969ed50 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -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 index 0000000000000..6a57b233516af --- /dev/null +++ b/src/crimson/common/log.cc @@ -0,0 +1,18 @@ +#include "log.h" + +static std::array 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 index 0000000000000..64ff33654ed43 --- /dev/null +++ b/src/crimson/common/log.h @@ -0,0 +1,6 @@ +#include +#include "common/subsys_types.h" + +namespace ceph { +seastar::logger& get_logger(int subsys); +} -- 2.39.5