Skip to content

Commit

Permalink
Remove SPDLOG_SOURCE_LOCATION support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Nov 29, 2024
1 parent 67628a4 commit 968dcfb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 108 deletions.
3 changes: 0 additions & 3 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
47 changes: 0 additions & 47 deletions include/spdlog/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,52 +108,6 @@ class SPDLOG_API logger {
}
}

#ifdef SPDLOG_SOURCE_LOCATION // off by default. define SPDLOG_SOURCE_LOCATION before including
// spdlog to enable.
template <typename... Args>
void trace(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::trace, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
void debug(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::debug, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
void info(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::info, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
void warn(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::warn, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
void error(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::err, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
void critical(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::critical, fmt.fmt_string, std::forward<Args>(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 <typename... Args>
void trace(format_string_t<Args...> fmt, Args &&...args) {
log(level::trace, fmt, std::forward<Args>(args)...);
Expand Down Expand Up @@ -191,7 +145,6 @@ class SPDLOG_API logger {
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); }
Expand Down
62 changes: 4 additions & 58 deletions include/spdlog/spdlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,60 +145,6 @@ inline void log(level lvl, format_string_t<Args...> 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 S, typename = is_convertible_to_sv<S>, typename... Args>
// inline void log(source_loc loc, level lvl, S fmt, Args &&...args) {
// default_logger_raw()->log(loc, lvl, fmt, std::forward<Args>(args)...);
// }
//
// template <typename S, typename = is_convertible_to_sv<S>, typename... Args>
// inline void log(level lvl, S fmt, Args &&...args) {
// default_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...);
// }

#ifdef SPDLOG_SOURCE_LOCATION
template <typename... Args>
inline void trace(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::trace, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
inline void debug(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::debug, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
inline void info(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::info, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
inline void warn(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, spdlog::level::warn, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
inline void error(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::err, fmt.fmt_string, std::forward<Args>(args)...);
}

template <typename... Args>
inline void critical(loc_with_fmt fmt, Args &&...args) {
log(fmt.loc, level::critical, fmt.fmt_string, std::forward<Args>(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 <typename... Args>
inline void trace(format_string_t<Args...> fmt, Args &&...args) {
log(level::trace, fmt, std::forward<Args>(args)...);
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 968dcfb

Please sign in to comment.