diff --git a/example/example.cpp b/example/example.cpp index 9dbb1c7c..0d8bdcd1 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -27,9 +27,6 @@ void custom_flags_example(); void file_events_example(); void replace_default_logger_example(); void mdc_example(); -// Uncomment to enable source location support. -// This will add filename/line/column info to the log (and in to the resulting binary so take care). -// #define SPDLOG_SOURCE_LOCATION #include "spdlog/cfg/env.h" // support for loading levels from the environment variable #include "spdlog/spdlog.h" diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 4da95764..524c3c39 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -108,52 +108,6 @@ public: } } -#ifdef SPDLOG_SOURCE_LOCATION // off by default. define SPDLOG_SOURCE_LOCATION before including - // spdlog to enable. - template - void trace(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::trace, fmt.fmt_string, std::forward(args)...); - } - - template - void debug(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::debug, fmt.fmt_string, std::forward(args)...); - } - - template - void info(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::info, fmt.fmt_string, std::forward(args)...); - } - - template - void warn(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::warn, fmt.fmt_string, std::forward(args)...); - } - - template - void error(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::err, fmt.fmt_string, std::forward(args)...); - } - - template - void critical(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::critical, fmt.fmt_string, std::forward(args)...); - } - - // log functions with no format string, just string - - void trace(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::trace, msg); } - - void debug(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::debug, msg); } - - void info(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::info, msg); } - - void warn(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::warn, msg); } - - void error(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::err, msg); } - - void critical(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::critical, msg); } -#else // without source location template void trace(format_string_t fmt, Args &&...args) { log(level::trace, fmt, std::forward(args)...); @@ -191,7 +145,6 @@ public: void warn(string_view_t msg) { log(level::warn, msg); } void error(string_view_t msg) { log(level::err, msg); } void critical(string_view_t msg) { log(level::critical, msg); } -#endif // SPDLOG_SOURCE_LOCATION // return true if logging is enabled for the given level. [[nodiscard]] bool should_log(level msg_level) const { return msg_level >= level_.load(std::memory_order_relaxed); } diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 68bea8cd..2d2f651b 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -145,60 +145,6 @@ inline void log(level lvl, format_string_t fmt, Args &&...args) { inline void log(level lvl, std::string_view msg) { default_logger_raw()->log(lvl, msg); } inline void log(source_loc loc, level lvl, std::string_view msg) { default_logger_raw()->log(loc, lvl, msg); } -// template , typename... Args> -// inline void log(source_loc loc, level lvl, S fmt, Args &&...args) { -// default_logger_raw()->log(loc, lvl, fmt, std::forward(args)...); -// } -// -// template , typename... Args> -// inline void log(level lvl, S fmt, Args &&...args) { -// default_logger_raw()->log(lvl, fmt, std::forward(args)...); -// } - -#ifdef SPDLOG_SOURCE_LOCATION -template -inline void trace(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::trace, fmt.fmt_string, std::forward(args)...); -} - -template -inline void debug(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::debug, fmt.fmt_string, std::forward(args)...); -} - -template -inline void info(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::info, fmt.fmt_string, std::forward(args)...); -} - -template -inline void warn(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, spdlog::level::warn, fmt.fmt_string, std::forward(args)...); -} - -template -inline void error(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::err, fmt.fmt_string, std::forward(args)...); -} - -template -inline void critical(loc_with_fmt fmt, Args &&...args) { - log(fmt.loc, level::critical, fmt.fmt_string, std::forward(args)...); -} - -// log functions with no format string, just string -inline void trace(std::string_view msg, source_loc loc = source_loc::current()) { log(loc, level::trace, msg); } - -inline void debug(std::string_view msg, source_loc loc = source_loc::current()) { log(loc, level::debug, msg); } - -inline void info(std::string_view msg, source_loc loc = source_loc::current()) { log(loc, level::info, msg); } - -inline void warn(std::string_view msg, source_loc loc = source_loc::current()) { log(loc, spdlog::level::warn, msg); } - -inline void error(std::string_view msg, source_loc loc = source_loc::current()) { log(loc, level::err, msg); } - -inline void critical(std::string_view msg, source_loc loc = source_loc::current()) { log(loc, level::critical, msg); } -#else template inline void trace(format_string_t fmt, Args &&...args) { log(level::trace, fmt, std::forward(args)...); @@ -241,7 +187,6 @@ inline void warn(std::string_view msg) { log(level::warn, msg); } inline void error(std::string_view msg) { log(level::err, msg); } inline void critical(std::string_view msg) { log(level::critical, msg); } -#endif } // namespace spdlog @@ -258,11 +203,12 @@ inline void critical(std::string_view msg) { log(level::critical, msg); } // SPDLOG_LEVEL_OFF // -#ifdef SPDLOG_SOURCE_LOCATION +#ifndef SPDLOG_NO_SOURCE_LOC #define SPDLOG_LOGGER_CALL(logger, level, ...) \ (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) -#else - #define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__) + #else + #define SPDLOG_LOGGER_CALL(logger, level, ...) \ + (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__) #endif #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE