From d387fdf96c24d343ee6a988d4632b4969215bf5e Mon Sep 17 00:00:00 2001 From: spaceman <1125934312@qq.com> Date: Sun, 25 Feb 2024 08:42:18 +0800 Subject: [PATCH 1/7] support MINGW (#3022) Under Windows 10, compiling with MINGW64 will report an error similar to https://github.com/gabime/spdlog/issues/1581 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4b3c1b2..b67bcb02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ endif() set(CMAKE_CXX_EXTENSIONS OFF) -if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS") +if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW") set(CMAKE_CXX_EXTENSIONS ON) endif() From 9a445245f15c8db04ab1f02f9ccade7a1a370c28 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 29 Feb 2024 08:55:37 +0200 Subject: [PATCH 2/7] Update ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abd96b3e..0aaa0932 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: - uses: actions/checkout@main - name: Setup run: | + add-apt-repository ppa:git-core/ppa apt-get update && apt-get install -y curl git pkg-config libsystemd-dev CMAKE_VERSION="3.24.2" curl -sSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh -o install-cmake.sh From 3f0e40071888de71c601fc1ce038b90a33075387 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 29 Feb 2024 09:04:33 +0200 Subject: [PATCH 3/7] Update ci.yml --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0aaa0932..fac4095e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,10 @@ jobs: - uses: actions/checkout@main - name: Setup run: | - add-apt-repository ppa:git-core/ppa - apt-get update && apt-get install -y curl git pkg-config libsystemd-dev + apt-get update + apt-get install python-software-properties software-properties-common + add-apt-repository ppa:git-core/ppa -y + apt-get install -y curl git pkg-config libsystemd-dev CMAKE_VERSION="3.24.2" curl -sSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh -o install-cmake.sh chmod +x install-cmake.sh From 75bfbb7c0c26bc7f74e23e7dccd138d0225a2366 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 29 Feb 2024 09:21:46 +0200 Subject: [PATCH 4/7] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fac4095e..fc4c73b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: - name: Setup run: | apt-get update - apt-get install python-software-properties software-properties-common + apt-get install software-properties-common add-apt-repository ppa:git-core/ppa -y apt-get install -y curl git pkg-config libsystemd-dev CMAKE_VERSION="3.24.2" From bc4b32958565b39c7e35188b74fa811714707fbe Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 29 Feb 2024 09:28:18 +0200 Subject: [PATCH 5/7] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc4c73b1..c29d9086 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: - name: Setup run: | apt-get update - apt-get install software-properties-common + apt-get install software-properties-common -y add-apt-repository ppa:git-core/ppa -y apt-get install -y curl git pkg-config libsystemd-dev CMAKE_VERSION="3.24.2" From 60faedb02566d3515c970b9303ddd041b107692d Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Thu, 29 Feb 2024 09:56:11 +0200 Subject: [PATCH 6/7] Update ci.yml --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c29d9086..bf8018a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,9 +25,7 @@ jobs: - uses: actions/checkout@main - name: Setup run: | - apt-get update - apt-get install software-properties-common -y - add-apt-repository ppa:git-core/ppa -y + apt-get update apt-get install -y curl git pkg-config libsystemd-dev CMAKE_VERSION="3.24.2" curl -sSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh -o install-cmake.sh From 5532231bbc31bbdf95ac15febdac0413ee1d07ad Mon Sep 17 00:00:00 2001 From: Leadbelly <48064852+BenLeadbetter@users.noreply.github.com> Date: Thu, 29 Feb 2024 08:53:56 +0000 Subject: [PATCH 7/7] feature: adds string view overloads for logger accessor (#3023) Co-authored-by: Ben Leadbetter --- include/spdlog/details/registry-inl.h | 16 ++++++++++++++++ include/spdlog/details/registry.h | 8 ++++++++ include/spdlog/spdlog-inl.h | 10 ++++++++++ include/spdlog/spdlog.h | 8 ++++++++ 4 files changed, 42 insertions(+) diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index da4a7de9..ab390aeb 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -84,6 +84,22 @@ SPDLOG_INLINE std::shared_ptr registry::get(const std::string &logger_na return found == loggers_.end() ? nullptr : found->second; } +#if __cplusplus >= 201703L // C++17 +SPDLOG_INLINE std::shared_ptr registry::get(std::string_view logger_name) { + std::lock_guard lock(logger_map_mutex_); + for (const auto &[key, val] : loggers_) { + if (key == logger_name) { + return val; + } + } + return nullptr; +} + +SPDLOG_INLINE std::shared_ptr registry::get(const char *logger_name) { + return get(std::string_view(logger_name)); +} +#endif + SPDLOG_INLINE std::shared_ptr registry::default_logger() { std::lock_guard lock(logger_map_mutex_); return default_logger_; diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 00492151..1e9e6bde 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -18,6 +18,10 @@ #include #include +#if __cplusplus >= 201703L // C++17 + #include +#endif + namespace spdlog { class logger; @@ -33,6 +37,10 @@ public: void register_logger(std::shared_ptr new_logger); void initialize_logger(std::shared_ptr new_logger); std::shared_ptr get(const std::string &logger_name); +#if __cplusplus >= 201703L // C++17 + std::shared_ptr get(std::string_view logger_name); + std::shared_ptr get(const char *logger_name); +#endif std::shared_ptr default_logger(); // Return raw ptr to the default logger. diff --git a/include/spdlog/spdlog-inl.h b/include/spdlog/spdlog-inl.h index 97c36222..54cdc2cc 100644 --- a/include/spdlog/spdlog-inl.h +++ b/include/spdlog/spdlog-inl.h @@ -20,6 +20,16 @@ SPDLOG_INLINE std::shared_ptr get(const std::string &name) { return details::registry::instance().get(name); } +#if __cplusplus >= 201703L // C++17 +SPDLOG_INLINE std::shared_ptr get(std::string_view name) { + return details::registry::instance().get(name); +} + +SPDLOG_INLINE std::shared_ptr get(const char *name) { + return details::registry::instance().get(name); +} +#endif + SPDLOG_INLINE void set_formatter(std::unique_ptr formatter) { details::registry::instance().set_formatter(std::move(formatter)); } diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index a8afbcec..d2982633 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -20,6 +20,10 @@ #include #include +#if __cplusplus >= 201703L // C++17 + #include +#endif + namespace spdlog { using default_factory = synchronous_factory; @@ -50,6 +54,10 @@ SPDLOG_API void initialize_logger(std::shared_ptr logger); // exist. // example: spdlog::get("my_logger")->info("hello {}", "world"); SPDLOG_API std::shared_ptr get(const std::string &name); +#if __cplusplus >= 201703L // C++17 +SPDLOG_API std::shared_ptr get(std::string_view name); +SPDLOG_API std::shared_ptr get(const char *name); +#endif // Set global formatter. Each sink in each logger will get a clone of this object SPDLOG_API void set_formatter(std::unique_ptr formatter);