diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 435e7ba8..8e6b7e1d 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -185,31 +185,6 @@ private: spdlog::details::source_location loc_; }; -template -struct value_wrapper -{ - SPDLOG_CONSTEVAL value_wrapper(const T& value, details::source_location loc = details::source_location::current()) - : value_{value} - , loc_{loc} - {} - T value() - { - return value_; - } - source_loc loc() - { - return source_loc{loc_.file_name(), loc_.line(), loc_.function_name()}; - } - operator T() - { - return value(); - } - -private: - T value_; - spdlog::details::source_location loc_; -}; - namespace sinks { class sink; } diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 61ee3e30..b8269304 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -98,9 +98,9 @@ public: } template - void log(level::level_enum lvl, const value_wrapper &msg) + void log(level::level_enum lvl, const T &msg) { - log(msg.loc(), lvl, msg.value()); + log(source_loc{}, lvl, msg); } // T cannot be statically converted to format string (including string_view/wstring_view) @@ -136,9 +136,9 @@ public: log_it_(log_msg, log_enabled, traceback_enabled); } - void log(level::level_enum lvl, value_wrapper msg) + void log(level::level_enum lvl, string_view_t msg) { - log(msg.loc(), lvl, msg.value()); + log(source_loc{}, lvl, msg); } template @@ -263,39 +263,39 @@ public: #endif template - void trace(const value_wrapper &msg) + void trace(const T &msg, details::source_location loc = details::source_location::current()) { - log(msg.loc(), level::trace, msg.value()); + log(source_loc{loc.file_name(), loc.line(), loc.function_name()}, level::trace, msg); } template - void debug(const value_wrapper &msg) + void debug(const T &msg, details::source_location loc = details::source_location::current()) { - log(msg.value(), level::debug, msg.value()); + log(source_loc{loc.file_name(), loc.line(), loc.function_name()}, level::debug, msg); } template - void info(const value_wrapper &msg) + void info(const T &msg, details::source_location loc = details::source_location::current()) { - log(msg.loc(), level::info, msg.value()); + log(source_loc{loc.file_name(), loc.line(), loc.function_name()}, level::info, msg); } template - void warn(const value_wrapper &msg) + void warn(const T &msg, details::source_location loc = details::source_location::current()) { - log(msg.loc(), level::warn, msg.value()); + log(source_loc{loc.file_name(), loc.line(), loc.function_name()}, level::warn, msg); } template - void error(const value_wrapper &msg) + void error(const T &msg, details::source_location loc = details::source_location::current()) { - log(msg.loc(), level::err, msg.value()); + log(source_loc{loc.file_name(), loc.line(), loc.function_name()}, level::err, msg); } template - void critical(const value_wrapper &msg) + void critical(const T &msg, details::source_location loc = details::source_location::current()) { - log(msg.loc(), level::critical, msg.value()); + log(source_loc{loc.file_name(), loc.line(), loc.function_name()}, 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 1fdf0e78..25c21dae 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(const value_wrapper &msg) +inline void trace(const T &msg, details::source_location loc = details::source_location::current()) { - default_logger_raw()->trace(msg); + default_logger_raw()->trace(msg, loc); } template -inline void debug(const value_wrapper &msg) +inline void debug(const T &msg, details::source_location loc = details::source_location::current()) { - default_logger_raw()->debug(msg); + default_logger_raw()->debug(msg, loc); } template -inline void info(const value_wrapper &msg) +inline void info(const T &msg, details::source_location loc = details::source_location::current()) { - default_logger_raw()->info(msg); + default_logger_raw()->info(msg, loc); } template -inline void warn(const value_wrapper &msg) +inline void warn(const T &msg, details::source_location loc = details::source_location::current()) { - default_logger_raw()->warn(msg); + default_logger_raw()->warn(msg, loc); } template -inline void error(const value_wrapper &msg) +inline void error(const T &msg, details::source_location loc = details::source_location::current()) { - default_logger_raw()->error(msg); + default_logger_raw()->error(msg, loc); } template -inline void critical(const value_wrapper &msg) +inline void critical(const T &msg, details::source_location loc = details::source_location::current()) { - default_logger_raw()->critical(msg); + default_logger_raw()->critical(msg, loc); } } // namespace spdlog