From 7c0afada60b869f87bd1016d21bcbd11c1ee5f5c Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 23 Sep 2023 02:02:50 +0300 Subject: [PATCH] check SPDLOG_SOURCE_LOCATION in macros and in runtime --- include/spdlog/common.h | 8 ++++---- include/spdlog/logger.h | 2 +- include/spdlog/spdlog.h | 4 ++-- include/spdlog/tweakme.h | 6 ++---- tests/test_source_location.cpp | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 6ec3f4de..bc433439 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -24,10 +24,10 @@ #if __cpp_lib_source_location >= 201907 # include -# define SPDLOG_STD_SOURCE_LOCATION +# define SPDLOG_HAVE_STD_SOURCE_LOCATION #elif __has_include() # include -# define SPDLOG_EXPERIMENTAL_SOURCE_LOCATION +# define SPDLOG_HAVE_EXPERIMENTAL_SOURCE_LOCATION #endif #ifdef SPDLOG_USE_STD_FORMAT @@ -254,12 +254,12 @@ struct source_loc , funcname{funcname_in} {} -#ifdef SPDLOG_STD_SOURCE_LOCATION +#ifdef SPDLOG_HAVE_STD_SOURCE_LOCATION static constexpr source_loc current(const std::source_location source_location = std::source_location::current()) { return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()}; } -#elif defined(SPDLOG_EXPERIMENTAL_SOURCE_LOCATION) +#elif defined(SPDLOG_HAVE_EXPERIMENTAL_SOURCE_LOCATION) static constexpr source_loc current( const std::experimental::source_location source_location = std::experimental::source_location::current()) { diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 407d604a..88d46c3f 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -129,7 +129,7 @@ public: } } -#ifdef SPDLOG_EMIT_SOURCE_LOCATION +#ifdef SPDLOG_SOURCE_LOCATION template void trace(loc_with_fmt fmt, Args &&...args) { diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 5d905bd6..0211301a 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -155,7 +155,7 @@ inline void log(log_level lvl, S fmt, Args &&...args) default_logger_raw()->log(lvl, fmt, std::forward(args)...); } -#ifdef SPDLOG_EMIT_SOURCE_LOCATION +#ifdef SPDLOG_SOURCE_LOCATION template inline void trace(loc_with_fmt fmt, Args &&...args) { @@ -306,7 +306,7 @@ inline void critical(string_view_t msg) // SPDLOG_LEVEL_OFF // -#ifndef SPDLOG_NO_SOURCE_LOC +#ifdef SPDLOG_SOURCE_LOCATION # define SPDLOG_LOGGER_CALL(logger, level, ...) \ (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) #else diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index 8b11176f..dd1be79e 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -20,10 +20,8 @@ /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -// Uncomment if source location logging is not needed. -// This will prevent spdlog from using __FILE__, __LINE__ and SPDLOG_FUNCTION -// -// #define SPDLOG_NO_SOURCE_LOC +// Uncomment if source location logging is needed./ +// #define SPDLOG_SOURCE_LOCATION /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/tests/test_source_location.cpp b/tests/test_source_location.cpp index 391d039c..d9a1f6b4 100644 --- a/tests/test_source_location.cpp +++ b/tests/test_source_location.cpp @@ -1,8 +1,8 @@ -#define SPDLOG_EMIT_SOURCE_LOCATION +#define SPDLOG_SOURCE_LOCATION #include "includes.h" #include "test_sink.h" -#if defined(SPDLOG_STD_SOURCE_LOCATION) || defined(SPDLOG_EXPERIMENTAL_SOURCE_LOCATION) +#if defined(SPDLOG_HAVE_STD_SOURCE_LOCATION) || defined(SPDLOG_HAVE_EXPERIMENTAL_SOURCE_LOCATION) using spdlog::details::os::default_eol;