File indexing completed on 2025-12-17 10:29:02
0001
0002
0003
0004 #pragma once
0005
0006 #if defined(_WIN32)
0007
0008 #include <spdlog/details/null_mutex.h>
0009 #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
0010 #include <spdlog/details/os.h>
0011 #endif
0012 #include <spdlog/sinks/base_sink.h>
0013
0014 #include <mutex>
0015 #include <string>
0016
0017
0018 #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
0019 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString);
0020 #else
0021 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
0022 #endif
0023 extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
0024
0025 namespace spdlog {
0026 namespace sinks {
0027
0028
0029
0030 template <typename Mutex>
0031 class msvc_sink : public base_sink<Mutex> {
0032 public:
0033 msvc_sink() = default;
0034 msvc_sink(bool check_debugger_present)
0035 : check_debugger_present_{check_debugger_present} {};
0036
0037 protected:
0038 void sink_it_(const details::log_msg &msg) override {
0039 if (check_debugger_present_ && !IsDebuggerPresent()) {
0040 return;
0041 }
0042 memory_buf_t formatted;
0043 base_sink<Mutex>::formatter_->format(msg, formatted);
0044 formatted.push_back('\0');
0045 #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
0046 wmemory_buf_t wformatted;
0047 details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted);
0048 OutputDebugStringW(wformatted.data());
0049 #else
0050 OutputDebugStringA(formatted.data());
0051 #endif
0052 }
0053
0054 void flush_() override {}
0055
0056 bool check_debugger_present_ = true;
0057 };
0058
0059 using msvc_sink_mt = msvc_sink<std::mutex>;
0060 using msvc_sink_st = msvc_sink<details::null_mutex>;
0061
0062 using windebug_sink_mt = msvc_sink_mt;
0063 using windebug_sink_st = msvc_sink_st;
0064
0065 }
0066 }
0067
0068 #endif