delete message wrapper and fix names

pull/2690/head
M. Galib Uludag 2 years ago
parent 6e56d9691a
commit 0154592e12

@ -142,6 +142,15 @@ struct source_loc
, line{line_in} , line{line_in}
, funcname{funcname_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 SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT
{ {
@ -155,19 +164,19 @@ struct source_loc
template<typename T, typename Char> template<typename T, typename Char>
struct format_string_wrapper 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} : fmt_{fmtstr}
, loc_{loc} , loc_{loc}
{} {}
#if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION >= 80000 #if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION >= 80000
SPDLOG_CONSTEXPR format_string_wrapper(fmt_runtime_string<Char> fmtstr, details::source_location loc = details::source_location::current()) SPDLOG_CONSTEXPR format_string_wrapper(fmt_runtime_string<Char> fmtstr, source_loc loc = source_loc{details::source_location::current()})
: fmt_{fmtstr} : fmt_{fmtstr}
, loc_{loc} , loc_{loc}
{} {}
#elif defined(SPDLOG_USE_STD_FORMAT) && SPDLOG_CPLUSPLUS >= 202002L #elif defined(SPDLOG_USE_STD_FORMAT) && SPDLOG_CPLUSPLUS >= 202002L
template <typename S> template <typename S>
requires std::is_convertible_v<S, T> requires std::is_convertible_v<S, T>
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} : fmt_{fmtstr}
, loc_{loc} , loc_{loc}
{} {}
@ -178,40 +187,12 @@ struct format_string_wrapper
} }
source_loc location() source_loc location()
{ {
return source_loc{loc_.file_name(), loc_.line(), loc_.function_name()}; return loc_;
} }
private: private:
T fmt_; T fmt_;
spdlog::details::source_location loc_; source_loc loc_;
};
template<typename T>
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_;
}; };
namespace sinks { namespace sinks {

@ -98,7 +98,7 @@ public:
} }
template<typename T> template<typename T>
void log(level::level_enum lvl, message_wrapper<T> msg) void log(level::level_enum lvl, const T &msg, source_loc loc = source_loc::current())
{ {
log(msg.location(), lvl, msg.message()); log(msg.location(), lvl, msg.message());
} }
@ -263,39 +263,39 @@ public:
#endif #endif
template<typename T> template<typename T>
void trace(message_wrapper<T> 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<typename T> template<typename T>
void debug(message_wrapper<T> 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<typename T> template<typename T>
void info(message_wrapper<T> 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<typename T> template<typename T>
void warn(message_wrapper<T> msg) void warn(const T &msg, source_loc loc = source_loc::current())
{ {
log(msg.location(), level::warn, msg); log(loc, level::warn, msg);
} }
template<typename T> template<typename T>
void error(message_wrapper<T> 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<typename T> template<typename T>
void critical(message_wrapper<T> 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. // return true logging is enabled for the given level.

@ -252,39 +252,39 @@ inline void critical(wformat_string_t<Args...> fmt, Args &&...args)
#endif #endif
template<typename T> template<typename T>
inline void trace(message_wrapper<T> 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<typename T> template<typename T>
inline void debug(message_wrapper<T> 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<typename T> template<typename T>
inline void info(message_wrapper<T> 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<typename T> template<typename T>
inline void warn(message_wrapper<T> 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<typename T> template<typename T>
inline void error(message_wrapper<T> 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<typename T> template<typename T>
inline void critical(message_wrapper<T> 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 } // namespace spdlog

Loading…
Cancel
Save