From 040874224bff7d61a09cbdb22fa318cbaf05afd7 Mon Sep 17 00:00:00 2001 From: Bailey Chittle <39804642+bachittle@users.noreply.github.com> Date: Tue, 21 Mar 2023 14:23:14 -0400 Subject: [PATCH 1/2] setting the cmake standard to 20 when using std format (#2680) --- CMakeLists.txt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3389c04b..3830dfe2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,10 @@ endif() # --------------------------------------------------------------------------------------- # Compiler config # --------------------------------------------------------------------------------------- -if(NOT CMAKE_CXX_STANDARD) +if(SPDLOG_USE_STD_FORMAT) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +elseif(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() @@ -256,11 +259,6 @@ if(SPDLOG_NO_EXCEPTIONS AND NOT MSVC) target_compile_options(spdlog PRIVATE -fno-exceptions) endif() -if(SPDLOG_USE_STD_FORMAT) - set(CMAKE_CXX_STANDARD 20) - set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() - # --------------------------------------------------------------------------------------- # Build binaries # --------------------------------------------------------------------------------------- From 42d1f40a185c92d8ffbfa9293c346507cb602a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SCC/=E6=A5=8A=E5=BF=97=E7=92=BF?= Date: Thu, 23 Mar 2023 16:24:48 +0800 Subject: [PATCH 2/2] Fix stdout_sink_base::log's behavior inconsistency (#2646) * Fix stdout_sink_base::log's behavior inconsistency It will flush every time when it if not defined _WIN32, but not in Windows family. We viewed the commit #48d4ed9 for fixing issue #1675 . It seems missing this flushing operation in mistake. * Use fflush at all operating system * Remove redundant fflush from stdout_sink_base --------- Co-authored-by: scc --- include/spdlog/sinks/stdout_sinks-inl.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/spdlog/sinks/stdout_sinks-inl.h b/include/spdlog/sinks/stdout_sinks-inl.h index 756734bf..9e8e6ddf 100644 --- a/include/spdlog/sinks/stdout_sinks-inl.h +++ b/include/spdlog/sinks/stdout_sinks-inl.h @@ -60,7 +60,6 @@ SPDLOG_INLINE void stdout_sink_base::log(const details::log_msg &m std::lock_guard lock(mutex_); memory_buf_t formatted; formatter_->format(msg, formatted); - ::fflush(file_); // flush in case there is something in this file_ already auto size = static_cast(formatted.size()); DWORD bytes_written = 0; bool ok = ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr) != 0; @@ -73,8 +72,8 @@ SPDLOG_INLINE void stdout_sink_base::log(const details::log_msg &m memory_buf_t formatted; formatter_->format(msg, formatted); ::fwrite(formatted.data(), sizeof(char), formatted.size(), file_); - ::fflush(file_); // flush every line to terminal #endif // WIN32 + ::fflush(file_); // flush every line to terminal } template