diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 7621309f..621336cc 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -197,11 +197,11 @@ struct source_loc , line(line) { } - // - // source_loc (const source_loc&) = default; - // source_loc& operator=(const source_loc&) = default; - // source_loc& operator=(source_loc&&) = default; - + + SPDLOG_CONSTEXPR bool empty() const + { + return line == 0; + } const char *filename; uint32_t line; }; diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index b236db9a..0212ede5 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -243,7 +243,7 @@ inline void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer } template -inline void spdlog::logger::log(source_location source, level::level_enum lvl, const wchar_t *fmt, const Args &... args) +inline void spdlog::logger::log(source_loc source, level::level_enum lvl, const wchar_t *fmt, const Args &... args) { if (!should_log(lvl)) { @@ -267,7 +267,7 @@ inline void spdlog::logger::log(source_location source, level::level_enum lvl, c template inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args) { - log(source_location{}, lvl, fmt, args...); + log(source_loc{}, lvl, fmt, args...); } template diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index e0e72081..5e25f590 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -817,6 +817,10 @@ public: void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override { + if (msg.source.empty()) + { + return; + } if (padinfo_.width_) { const auto text_size = std::char_traits::length(msg.source.filename) + fmt_helper::count_digits(msg.source.line) + 1; @@ -842,6 +846,10 @@ public: void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override { + if (msg.source.empty()) + { + return; + } scoped_pad p(msg.source.filename, padinfo_, dest); fmt_helper::append_string_view(msg.source.filename, dest); } @@ -855,7 +863,10 @@ public: void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override { - + if (msg.source.empty()) + { + return; + } if (padinfo_.width_) { const size_t field_size = fmt::internal::count_digits(msg.source.line); diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 0f75a6f0..1b762429 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -79,7 +79,7 @@ public: void log(level::level_enum lvl, const wchar_t *fmt, const Args &... args); template - void log(source_location soruce, level::level_enum lvl, const wchar_t *fmt, const Args &... args); + void log(source_loc soruce, level::level_enum lvl, const wchar_t *fmt, const Args &... args); template void trace(const wchar_t *fmt, const Args &... args); diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 301ae97d..923b5c3d 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -309,19 +309,20 @@ inline void critical(const wchar_t *fmt, const Args &... args) // SPDLOG_LEVEL_OFF // -#define SPDLOG_LOGGER_LOG(logger, level, ...) logger->log(spdlog::source_loc{__FILE__, __LINE__}, level, __VA_ARGS__) #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE -#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_LOG(logger, spdlog::level::trace, __VA_ARGS__) -#define SPDLOG_TRACE(...) SPDLOG_LOGGER_LOG(spdlog::default_logger_raw(), spdlog::level::trace, __VA_ARGS__) +#define SPDLOG_LOGGER_TRACE(logger, ...) logger->log(spdlog::source_loc{__FILE__, __LINE__}, spdlog::level::trace, __VA_ARGS__) +#define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) #else #define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 #define SPDLOG_TRACE(...) (void)0 #endif +#define SPDLOG_LOGGER_LOG(logger, level, ...) logger->log(level, __VA_ARGS__) + #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG #define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_LOG(logger, spdlog::level::debug, __VA_ARGS__) -#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_LOG(spdlog::default_logger_raw(), spdlog::level::debug, __VA_ARGS__) +#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) #else #define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 #define SPDLOG_DEBUG(...) (void)0 @@ -329,7 +330,7 @@ inline void critical(const wchar_t *fmt, const Args &... args) #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO #define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_LOG(logger, spdlog::level::info, __VA_ARGS__) -#define SPDLOG_INFO(...) SPDLOG_LOGGER_LOG(spdlog::default_logger_raw(), spdlog::level::info, __VA_ARGS__) +#define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__) #else #define SPDLOG_LOGGER_INFO(logger, ...) (void)0 #define SPDLOG_INFO(...) (void)0 @@ -337,7 +338,7 @@ inline void critical(const wchar_t *fmt, const Args &... args) #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN #define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_LOG(logger, spdlog::level::warn, __VA_ARGS__) -#define SPDLOG_WARN(...) SPDLOG_LOGGER_LOG(spdlog::default_logger_raw(), spdlog::level::warn, __VA_ARGS__) +#define SPDLOG_WARN(...) SPDLOG_ACTIVE_LEVEL(spdlog::default_logger_raw(), __VA_ARGS__) #else #define SPDLOG_LOGGER_WARN(logger, ...) (void)0 #define SPDLOG_WARN(...) (void)0 @@ -345,7 +346,7 @@ inline void critical(const wchar_t *fmt, const Args &... args) #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR #define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_LOG(logger, spdlog::level::err, __VA_ARGS__) -#define SPDLOG_ERROR(...) SPDLOG_LOGGER_LOG(spdlog::default_logger_raw(), spdlog::level::err, __VA_ARGS__) +#define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__) #else #define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 #define SPDLOG_ERROR(...) (void)0 @@ -353,7 +354,7 @@ inline void critical(const wchar_t *fmt, const Args &... args) #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL #define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_LOG(logger, spdlog::level::critical, __VA_ARGS__) -#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_LOG(spdlog::default_logger_raw(), spdlog::level::critical, __VA_ARGS__) +#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) #else #define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 #define SPDLOG_CRITICAL(...) (void)0