From 0154592e126580bc1b9b85c5c338450f826bfd09 Mon Sep 17 00:00:00 2001 From: "M. Galib Uludag" Date: Sun, 18 Jun 2023 16:59:36 +0000 Subject: [PATCH] delete message wrapper and fix names --- include/spdlog/common.h | 47 ++++++++++++----------------------------- include/spdlog/logger.h | 26 +++++++++++------------ include/spdlog/spdlog.h | 24 ++++++++++----------- 3 files changed, 39 insertions(+), 58 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 7569bbf5..0841329e 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -142,6 +142,15 @@ struct source_loc , line{line_in} , funcname{funcname_in} {} + SPDLOG_CONSTEXPR source_loc(details::source_location location) + : filename{location.file_name()} + , line{location.line()} + , funcname{location.function_name()} + {} + SPDLOG_CONSTEXPR source_loc static current(details::source_location cur = details::source_location::current()) + { + return source_loc{cur.file_name(), cur.line(), cur.function_name()}; + } SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT { @@ -155,19 +164,19 @@ struct source_loc template struct format_string_wrapper { - SPDLOG_CONSTEVAL format_string_wrapper(const Char* fmtstr, details::source_location loc = details::source_location::current()) + SPDLOG_CONSTEVAL format_string_wrapper(const Char* fmtstr, source_loc loc = source_loc{details::source_location::current()}) : fmt_{fmtstr} , loc_{loc} {} #if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION >= 80000 - SPDLOG_CONSTEXPR format_string_wrapper(fmt_runtime_string fmtstr, details::source_location loc = details::source_location::current()) + SPDLOG_CONSTEXPR format_string_wrapper(fmt_runtime_string fmtstr, source_loc loc = source_loc{details::source_location::current()}) : fmt_{fmtstr} , loc_{loc} {} #elif defined(SPDLOG_USE_STD_FORMAT) && SPDLOG_CPLUSPLUS >= 202002L template requires std::is_convertible_v - SPDLOG_CONSTEXPR format_string_wrapper(S fmtstr, details::source_location loc = details::source_location::current()) + SPDLOG_CONSTEXPR format_string_wrapper(S fmtstr, source_loc loc = source_loc{details::source_location::current()}) : fmt_{fmtstr} , loc_{loc} {} @@ -178,40 +187,12 @@ struct format_string_wrapper } source_loc location() { - return source_loc{loc_.file_name(), loc_.line(), loc_.function_name()}; + return loc_; } private: T fmt_; - spdlog::details::source_location loc_; -}; - -template -struct message_wrapper -{ - message_wrapper(T msg, details::source_location loc = details::source_location::current()) - : msg_{msg} - , loc_{loc} - {} - - T message() - { - return msg_; - } - - source_loc location() - { - return source_loc{loc_.file_name(), loc_.line(), loc_.function_name()}; - } - - operator T() - { - return msg_; - } - -private: - T msg_; - spdlog::details::source_location loc_; + source_loc loc_; }; namespace sinks { diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 7e1247d2..fc11cc28 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -98,7 +98,7 @@ public: } template - void log(level::level_enum lvl, message_wrapper msg) + void log(level::level_enum lvl, const T &msg, source_loc loc = source_loc::current()) { log(msg.location(), lvl, msg.message()); } @@ -263,39 +263,39 @@ public: #endif template - void trace(message_wrapper msg) + void trace(const T &msg, source_loc loc = source_loc::current()) { - log(msg.location(), level::trace, msg.message()); + log(loc, level::trace, msg); } template - void debug(message_wrapper msg) + void debug(const T &msg, source_loc loc = source_loc::current()) { - log(msg.location(), level::debug, msg.message()); + log(loc, level::debug, msg); } template - void info(message_wrapper msg) + void info(const T &msg, source_loc loc = source_loc::current()) { - log(msg.location(), level::info, msg.message()); + log(loc, level::info, msg); } template - void warn(message_wrapper msg) + void warn(const T &msg, source_loc loc = source_loc::current()) { - log(msg.location(), level::warn, msg); + log(loc, level::warn, msg); } template - void error(message_wrapper msg) + void error(const T &msg, source_loc loc = source_loc::current()) { - log(msg.location(), level::err, msg.message()); + log(loc, level::err, msg); } template - void critical(message_wrapper msg) + void critical(const T &msg, source_loc loc = source_loc::current()) { - log(msg.location(), level::critical, msg.message()); + log(loc, level::critical, msg); } // return true logging is enabled for the given level. diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index bedfdb14..fa71fe43 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -252,39 +252,39 @@ inline void critical(wformat_string_t fmt, Args &&...args) #endif template -inline void trace(message_wrapper msg) +inline void trace(const T &msg, source_loc loc = source_loc::current()) { - default_logger_raw()->trace(msg); + default_logger_raw()->trace(msg, loc); } template -inline void debug(message_wrapper msg) +inline void debug(const T &msg, source_loc loc = source_loc::current()) { - default_logger_raw()->debug(msg); + default_logger_raw()->debug(msg, loc); } template -inline void info(message_wrapper msg) +inline void info(const T &msg, source_loc loc = source_loc::current()) { - default_logger_raw()->info(msg); + default_logger_raw()->info(msg, loc); } template -inline void warn(message_wrapper msg) +inline void warn(const T &msg, source_loc loc = source_loc::current()) { - default_logger_raw()->warn(msg); + default_logger_raw()->warn(msg, loc); } template -inline void error(message_wrapper msg) +inline void error(const T &msg, source_loc loc = source_loc::current()) { - default_logger_raw()->error(msg); + default_logger_raw()->error(msg, loc); } template -inline void critical(message_wrapper msg) +inline void critical(const T &msg, source_loc loc = source_loc::current()) { - default_logger_raw()->critical(msg); + default_logger_raw()->critical(msg, loc); } } // namespace spdlog