From 47b7e7c736fbf58e2e62d18f18b72209641f0c32 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 12 Feb 2024 22:02:31 +0100 Subject: [PATCH 01/10] Fix typos found by codespell (#3011) --- include/spdlog/sinks/qt_sinks.h | 6 +++--- tests/test_errors.cpp | 2 +- tests/test_file_helper.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/spdlog/sinks/qt_sinks.h b/include/spdlog/sinks/qt_sinks.h index 87a962d3e..d319e8473 100644 --- a/include/spdlog/sinks/qt_sinks.h +++ b/include/spdlog/sinks/qt_sinks.h @@ -4,7 +4,7 @@ #pragma once // -// Custom sink for QPlainTextEdit or QTextEdit and its childs(QTextBrowser... +// Custom sink for QPlainTextEdit or QTextEdit and its children (QTextBrowser... // etc) Building and using requires Qt library. // // Warning: the qt_sink won't be notified if the target widget is destroyed. @@ -56,7 +56,7 @@ class qt_sink : public base_sink { std::string meta_method_; }; -// QT color sink to QTextEdit. +// Qt color sink to QTextEdit. // Color location is determined by the sink log pattern like in the rest of spdlog sinks. // Colors can be modified if needed using sink->set_color(level, qtTextCharFormat). // max_lines is the maximum number of lines that the sink will hold before removing the oldest @@ -282,7 +282,7 @@ inline std::shared_ptr qt_logger_st(const std::string &logger_name, return Factory::template create(logger_name, qt_object, meta_method); } -// log to QTextEdit with colorize output +// log to QTextEdit with colorized output template inline std::shared_ptr qt_color_logger_mt(const std::string &logger_name, QTextEdit *qt_text_edit, diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index 7dde919d9..1c24cabc2 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -19,7 +19,7 @@ class failing_sink : public spdlog::sinks::base_sink { }; struct custom_ex {}; -#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support tuntime strings +#if !defined(SPDLOG_USE_STD_FORMAT) // std format doesn't fully support runtime strings TEST_CASE("default_error_handler", "[errors]") { prepare_logdir(); spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG); diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp index de7d51d91..56ee75e3e 100644 --- a/tests/test_file_helper.cpp +++ b/tests/test_file_helper.cpp @@ -152,7 +152,7 @@ TEST_CASE("file_event_handlers", "[file_helper]") { helper.reopen(true); events.clear(); } - // make sure that the file_helper destrcutor calls the close callbacks if needed + // make sure that the file_helper destructor calls the close callbacks if needed REQUIRE(events == std::vector{flags::before_close, flags::after_close}); REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n"); } From fe79bfcc51552636f6447a9ad0f214da724f051a Mon Sep 17 00:00:00 2001 From: cohdan <145435761+cohdan@users.noreply.github.com> Date: Wed, 14 Feb 2024 21:48:44 +0200 Subject: [PATCH 02/10] Expose the flusher thread object to user in order to allow setting of thread name and thread affinity when needed (#3009) * Expose the flusher thread object to user in order to allow setting of thread name and thread affinity when needed * Code review fix - periodic_worker thread getter should return a reference and not a pointer --- include/spdlog/details/periodic_worker.h | 1 + include/spdlog/details/registry.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index d05245cb1..d647b66ee 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -38,6 +38,7 @@ class SPDLOG_API periodic_worker { } }); } + std::thread &get_thread() { return worker_thread_; } periodic_worker(const periodic_worker &) = delete; periodic_worker &operator=(const periodic_worker &) = delete; // stop the worker thread and join it diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 56a6886ec..1dff8cdb2 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -68,6 +68,8 @@ class SPDLOG_API registry { periodic_flusher_ = details::make_unique(clbk, interval); } + std::unique_ptr &get_flusher() { std::lock_guard lock(flusher_mutex_); return periodic_flusher_; } + void set_error_handler(err_handler handler); void apply_all(const std::function)> &fun); From 134f9194bb93072b72b8cfa27ac3bb30a0fb5b57 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Wed, 14 Feb 2024 21:52:21 +0200 Subject: [PATCH 03/10] Update registry.h code formatting --- include/spdlog/details/registry.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index 1dff8cdb2..004921510 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -68,7 +68,10 @@ class SPDLOG_API registry { periodic_flusher_ = details::make_unique(clbk, interval); } - std::unique_ptr &get_flusher() { std::lock_guard lock(flusher_mutex_); return periodic_flusher_; } + std::unique_ptr &get_flusher() { + std::lock_guard lock(flusher_mutex_); + return periodic_flusher_; + } void set_error_handler(err_handler handler); 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 04/10] 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 d4b3c1b2b..b67bcb02f 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 05/10] 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 abd96b3e6..0aaa0932d 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 06/10] 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 0aaa0932d..fac4095e9 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 07/10] 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 fac4095e9..fc4c73b18 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 08/10] 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 fc4c73b18..c29d90868 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 09/10] 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 c29d90868..bf8018a35 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 10/10] 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 da4a7de97..ab390aeb8 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 004921510..1e9e6bde7 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 @@ class SPDLOG_API registry { 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 97c362222..54cdc2ccc 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 a8afbcec4..d2982633f 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);