From 513e49b396f1c4a2a1d6e264af90535c58339904 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 29 Jun 2019 21:34:39 +0800 Subject: [PATCH] common/dout.h: extract log level mapping out so we can reuse it. Signed-off-by: Kefu Chai --- src/common/dout.h | 14 ++------------ src/crimson/common/log.h | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/common/dout.h b/src/common/dout.h index 4fec750f57c21..415678e4992d6 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -127,18 +127,8 @@ struct is_dynamic> : public std::true_type {}; 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 <= 20) { \ - _logger.debug(_s.c_str()); \ - } else { \ - _logger.trace(_s.c_str()); \ - } \ + _logger.log(ceph::to_log_level(_lv), \ + _out.str().c_str()); \ } \ } while (0) #else diff --git a/src/crimson/common/log.h b/src/crimson/common/log.h index 64ff33654ed43..9f1949fd25414 100644 --- a/src/crimson/common/log.h +++ b/src/crimson/common/log.h @@ -1,6 +1,21 @@ +#pragma once + #include #include "common/subsys_types.h" namespace ceph { seastar::logger& get_logger(int subsys); +static inline seastar::log_level to_log_level(int level) { + if (level < 0) { + return seastar::log_level::error; + } else if (level < 1) { + return seastar::log_level::warn; + } else if (level < 5) { + return seastar::log_level::info; + } else if (level <= 20) { + return seastar::log_level::debug; + } else { + return seastar::log_level::trace; + } +} } -- 2.39.5