Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gabime/spdlog.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgabime <gmelman1@gmail.com>2022-11-01 01:52:39 +0300
committergabime <gmelman1@gmail.com>2022-11-01 01:52:39 +0300
commitbd5a81df7092c899b63c3f1bc3792a5f97113cc4 (patch)
tree40ef215325a49c2ce5f6b87d1bd0c3d7d9e27f4f
parent4accce5d7b57c268ea37e566a268e51a485b8581 (diff)
Check IsDebuggerPresent in msvc_sink before doing work. Fix #2408
-rw-r--r--include/spdlog/sinks/msvc_sink.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h
index b1dfd305..09008b78 100644
--- a/include/spdlog/sinks/msvc_sink.h
+++ b/include/spdlog/sinks/msvc_sink.h
@@ -1,8 +1,9 @@
-// Copyright(c) 2016 Alexander Dalshov.
+// Copyright(c) 2016 Alexander Dalshov & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
+
#if defined(_WIN32)
# include <spdlog/details/null_mutex.h>
@@ -13,6 +14,7 @@
// Avoid including windows.h (https://stackoverflow.com/a/30741042)
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
+extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
namespace spdlog {
namespace sinks {
@@ -24,10 +26,16 @@ class msvc_sink : public base_sink<Mutex>
{
public:
msvc_sink() = default;
+ msvc_sink(bool check_ebugger_present)
+ : check_debbugger_present_{check_ebugger_present} {};
protected:
void sink_it_(const details::log_msg &msg) override
{
+ if (check_debbugger_present_ && !IsDebuggerPresent())
+ {
+ return;
+ }
memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted);
formatted.push_back('\0'); // add a null terminator for OutputDebugStringA
@@ -35,6 +43,8 @@ protected:
}
void flush_() override {}
+
+ bool check_debbugger_present_ = true;
};
using msvc_sink_mt = msvc_sink<std::mutex>;