1 // 2 // Copyright(c) 2016 Alexander Dalshov. 3 // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 // 5 6 #pragma once 7 8 #if defined(_WIN32) 9 10 #include "spdlog/details/null_mutex.h" 11 #include "spdlog/sinks/base_sink.h" 12 13 #include <winbase.h> 14 15 #include <mutex> 16 #include <string> 17 18 namespace spdlog { 19 namespace sinks { 20 /* 21 * MSVC sink (logging using OutputDebugStringA) 22 */ 23 template<typename Mutex> 24 class msvc_sink : public base_sink<Mutex> 25 { 26 public: msvc_sink()27 explicit msvc_sink() {} 28 29 protected: 30 void sink_it_(const details::log_msg &msg) override 31 { 32 33 fmt::memory_buffer formatted; 34 sink::formatter_->format(msg, formatted); 35 OutputDebugStringA(fmt::to_string(formatted).c_str()); 36 } 37 38 void flush_() override {} 39 }; 40 41 using msvc_sink_mt = msvc_sink<std::mutex>; 42 using msvc_sink_st = msvc_sink<details::null_mutex>; 43 44 using windebug_sink_mt = msvc_sink_mt; 45 using windebug_sink_st = msvc_sink_st; 46 47 } // namespace sinks 48 } // namespace spdlog 49 50 #endif 51